一个动态波浪纹Android界面

技术一个动态波浪纹Android界面 一个动态波浪纹Android界面IndexActivity.javapackage com.example.rubikrobot;import androidx.a

一个动态波浪纹机器人界面

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

(0)

相关推荐

  • 如何使用Hibernate+Struts实现J2EE应用开发

    技术如何使用Hibernate+Struts实现J2EE应用开发这篇文章主要为大家展示了“如何使用Hibernate+Struts实现J2EE应用开发”,内容简而易懂,条理清晰,希望能够帮助大家解决疑惑,下面让小编带领大

    攻略 2021年12月8日
  • CF1506A Strange Table 题解

    技术CF1506A Strange Table 题解 CF1506A Strange Table 题解CF1506A Strange Table 题解Content
    给定一个 \(n\times m\)

    礼包 2021年12月16日
  • Redis对于过期键的清除策略有哪些

    技术Redis对于过期键的清除策略有哪些本篇内容主要讲解“Redis对于过期键的清除策略有哪些”,感兴趣的朋友不妨来看看。本文介绍的方法操作简单快捷,实用性强。下面就让小编来带大家学习“Redis对于过期键的清除策略有哪

    攻略 2021年11月24日
  • 支付宝转账记录怎么查,支付宝转账记录怎么查

    技术支付宝转账记录怎么查,支付宝转账记录怎么查支付宝转账记录怎么查?现在我们很多时候都会使用支付宝的转账功能。不过有的时候我们会忘记转账给谁了转账了多少钱,那么支付宝转账记录怎么查看呢?支付宝转账记录又在哪查看呢?现在就

    生活 2021年10月28日
  • Python光学仿真数值分析怎么求解波动方程绘制波包变化图

    技术Python光学仿真数值分析怎么求解波动方程绘制波包变化图本篇内容介绍了“Python光学仿真数值分析怎么求解波动方程绘制波包变化图”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大

    攻略 2021年10月20日
  • 如何看iphone里的数据分析(怎么能看懂iphone的数据分析)

    技术如何进行iPhone步行数据的分析这期内容当中小编将会给大家带来有关如何进行iPhone步行数据的分析,文章内容丰富且以专业的角度为大家分析和叙述,阅读完这篇文章希望大家可以有所收获。我将展示如何利用 pandas

    攻略 2021年12月20日