一个动态波浪纹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)

相关推荐

  • naalo2怎么读,NaAlO2的物质名称是什么

    技术naalo2怎么读,NaAlO2的物质名称是什么NaAlO2 偏铝酸钠 铝和氢氧化钠2Al+2H2O+2NaOH=2NaAlO2+3H2 氧化铝和氢氧化钠也可以Al2O3+2NaOH=2NaAlO2+H2O化学式Na

    生活 2021年10月19日
  • 任劳任怨的意思,默默无闻任劳任怨是什么意思

    技术任劳任怨的意思,默默无闻任劳任怨是什么意思【拼音】任劳任怨的意思:mò mò wú wén【释义】:无声无息,没人知道。指没有什么名声。
    【出处】:《晋书·祖纳传》:“仆虽无无,非志不立,故疾没世而无闻焉。”
    【例句

    生活 2021年10月23日
  • C++为什么要保持默认操作的一贯性

    技术C++为什么要保持默认操作的一贯性这篇文章主要介绍“C++为什么要保持默认操作的一贯性”,在日常操作中,相信很多人在C++为什么要保持默认操作的一贯性问题上存在疑惑,小编查阅了各式资料,整理出简单好用的操作方法,希望

    攻略 2021年11月29日
  • MySQL如何快速查看原始SQL语句

    技术MySQL如何快速查看原始SQL语句这篇文章主要讲解了“MySQL如何快速查看原始SQL语句”,文中的讲解内容简单清晰,易于学习与理解,下面请大家跟着小编的思路慢慢深入,一起来研究和学习“MySQL如何快速查看原始S

    攻略 2021年11月9日
  • netty组件化设计(net有类似netty的框架吗)

    技术基于NIO的网络编程框架Netty有哪些组件本篇内容介绍了“基于NIO的网络编程框架Netty有哪些组件”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧

    攻略 2021年12月21日
  • mysql 发生系统错误1067(mysql数据库1067错误是怎么回事)

    技术mysql出现服务1067错误怎么办这篇文章将为大家详细讲解有关mysql出现服务1067错误怎么办,小编觉得挺实用的,因此分享给大家做个参考,希望大家阅读完这篇文章后可以有所收获。 my

    攻略 2021年12月22日