一个动态波浪纹机器人界面
IndexActivity.java
包裹。com。例子。rubikrobot
导入androidx。app compat。app。AppCompactivity
导入安卓。动画。动画师;
导入安卓。动画。动画师集;
导入安卓。动画。objectanimator
导入安卓。内容。意图;
导入安卓。操作系统。捆绑;
导入安卓。操作系统。处理程序;
导入安卓。操作系统。活套;
导入安卓。查看。查看;
导入安卓。查看。窗户;
导入安卓。查看。动画。加速减速插值器;
导入安卓。小部件。按钮;
导入安卓。小部件。imageview
导入Java。乌提尔。ArrayList
公共类索引活动扩展了AppCompatActivity {
私人按钮按钮;
@覆盖
受保护的无效创建(捆绑保存实例){ 0
超级棒。oncreate(savedInstanceState);
请求窗口功能(窗口。特征_编号_标题);
setContentView(r . layout。activity _ index);
final RippleBackground RippleBackground=findweid(r . id。内容);
最终处理程序=新处理程序(looper。my loop er());
//Founddevice=(ImageView)FindeViewByID(r . id。found device);
button=findwiewbyid(r . id。中心图像);
ripplebackground。startrippleanimation();
意向意向=新意向();
button.setOnClickListener(新视图OnClickListener(){ 0
@覆盖
公共空间点击(视图v){ 0
意图。setclass(indexactivity。这个,主要活动。类);
startActivity(意图);
}
});
}
}
RippleBackground.java
包裹。com。例子。rubikrobot
导入安卓。动画。动画师;
导入安卓。动画。动画师集;
导入安卓。动画。objectanimator
导入安卓。内容。语境;
导入安卓。内容。RES . typedarray
导入安卓。图形。帆布;
导入安卓。图形。油漆;
导入安卓。乌提尔。属性集;
导入安卓。查看。查看;
导入安卓。查看。动画。加速减速插值器;
导入安卓。小部件。相对布局;
导入Java。乌提尔。ArrayList
公共类RippleBackground扩展了相对视频
私有静态最终int DEFAULT _ RIPPLE _ COUNT=6;
私有静态最终int DEFAULT _ DURATION _ TIME=3000
私有静态最终浮点DEFAULT _ SCALE=6.0f
私人员工
tic final int DEFAULT_FILL_TYPE=0;
private int rippleColor;
private float rippleStrokeWidth;
private float rippleRadius;
private int rippleDurationTime;
private int rippleAmount;
private int rippleDelay;
private float rippleScale;
private int rippleType;
private Paint paint;
private boolean animationRunning=false;
private AnimatorSet animatorSet;
private ArrayListAnimator animatorList;
private LayoutParams rippleParams;
private ArrayListRippleView rippleViewList=new ArrayListRippleView();
public RippleBackground(Context context) {
super(context);
}
public RippleBackground(Context context, AttributeSet attrs) {
super(context, attrs);
init(context, attrs);
}
public RippleBackground(Context context, AttributeSet attrs, int defStyleAttr) {
super(context, attrs, defStyleAttr);
init(context, attrs);
}
private void init(final Context context, final AttributeSet attrs) {
if (isInEditMode())
return;
if (null == attrs) {
throw new IllegalArgumentException("Attributes should be provided to this view,");
}
final TypedArray typedArray = context.obtainStyledAttributes(attrs, R.styleable.RippleBackground);
rippleColor=typedArray.getColor(R.styleable.RippleBackground_rb_color, getResources().getColor(R.color.rippelColor));
rippleStrokeWidth=typedArray.getDimension(R.styleable.RippleBackground_rb_strokeWidth, getResources().getDimension(R.dimen.rippleStrokeWidth));
rippleRadius=typedArray.getDimension(R.styleable.RippleBackground_rb_radius,getResources().getDimension(R.dimen.rippleRadius));
rippleDurationTime=typedArray.getInt(R.styleable.RippleBackground_rb_duration,DEFAULT_DURATION_TIME);
rippleAmount=typedArray.getInt(R.styleable.RippleBackground_rb_rippleAmount,DEFAULT_RIPPLE_COUNT);
rippleScale=typedArray.getFloat(R.styleable.RippleBackground_rb_scale,DEFAULT_SCALE);
rippleType=typedArray.getInt(R.styleable.RippleBackground_rb_type,DEFAULT_FILL_TYPE);
typedArray.recycle();
rippleDelay=rippleDurationTime/rippleAmount;
paint = new Paint();
paint.setAntiAlias(true);
if(rippleType==DEFAULT_FILL_TYPE){
rippleStrokeWidth=0;
paint.setStyle(Paint.Style.FILL);
}else
paint.setStyle(Paint.Style.STROKE);
paint.setColor(rippleColor);
rippleParams=new LayoutParams((int)(2*(rippleRadius+rippleStrokeWidth)),(int)(2*(rippleRadius+rippleStrokeWidth)));
rippleParams.addRule(CENTER_IN_PARENT, TRUE);
animatorSet = new AnimatorSet();
animatorSet.setInterpolator(new AccelerateDecelerateInterpolator());
animatorList=new ArrayListAnimator();
for(int i=0;irippleAmount;i++){
RippleView rippleView=new RippleView(getContext());
addView(rippleView,rippleParams);
rippleViewList.add(rippleView);
final ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleX", 1.0f, rippleScale);
scaleXAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleXAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleXAnimator.setStartDelay(i * rippleDelay);
scaleXAnimator.setDuration(rippleDurationTime);
animatorList.add(scaleXAnimator);
final ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(rippleView, "ScaleY", 1.0f, rippleScale);
scaleYAnimator.setRepeatCount(ObjectAnimator.INFINITE);
scaleYAnimator.setRepeatMode(ObjectAnimator.RESTART);
scaleYAnimator.setStartDelay(i * rippleDelay);
scaleYAnimator.setDuration(rippleDurationTime);
animatorList.add(scaleYAnimator);
final ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(rippleView, "Alpha", 1.0f, 0f);
alphaAnimator.setRepeatCount(ObjectAnimator.INFINITE);
alphaAnimator.setRepeatMode(ObjectAnimator.RESTART);
alphaAnimator.setStartDelay(i * rippleDelay);
alphaAnimator.setDuration(rippleDurationTime);
animatorList.add(alphaAnimator);
}
animatorSet.playTogether(animatorList);
}
private class RippleView extends View{
public RippleView(Context context) {
super(context);
this.setVisibility(View.INVISIBLE);
}
@Override
protected void onDraw(Canvas canvas) {
int radius=(Math.min(getWidth(),getHeight()))/2;
canvas.drawCircle(radius,radius,radius-rippleStrokeWidth,paint);
}
}
public void startRippleAnimation(){
if(!isRippleAnimationRunning()){
for(RippleView rippleView:rippleViewList){
rippleView.setVisibility(VISIBLE);
}
animatorSet.start();
animationRunning=true;
}
}
public void stopRippleAnimation(){
if(isRippleAnimationRunning()){
animatorSet.end();
animationRunning=false;
}
}
public boolean isRippleAnimationRunning(){
return animationRunning;
}
}
layout
xml version="1.0" encoding="utf-8" com.example.rubikrobot.RippleBackground xmlns:andro xmlns:app="http://schemas.android.com/apk/res-auto" android:layout_width="match_parent" android:layout_height="match_parent" android:background="#A2DAEC" android: app:rb_color="#0099CC" app:rb_radius="32dp" app:rb_rippleAmount="6" app:rb_duration="3000" app:rb_scale="6" Button android:layout_width="64dp" android:layout_height="64dp" android:layout_centerInParent="true" android: android:text="启动" android:textColor="@color/white" android:background="@drawable/ic_blue" / /com.example.rubikrobot.RippleBackground
效果图:
这是三个主要文件,剩下的没有展示。
链接:Github
参考文档以及链接均来自于:【Android开发】安卓炫酷效果集合
内容来源网络,如有侵权,联系删除,本文地址:https://www.230890.com/zhan/84605.html