android仿ios动画,Android 高仿iOS加载动画

效果图

512497a7c35c

gggggg.gif

无需多言, 代码

java 类 (直接拷贝使用)

/**

* Project: android

* ClassName: LoadingView

* Date: 2020/7/28 15:34

* Creator: voisen

* Email: voisen@icloud.com

* Version: 1.0

* Description: this is LoadingView description !

*/

public class LoadingView extends View {

private String TAG = "LoadingView";

//自定义变量区域

private int num = 12;

private float strokeWidth = 5;

private int changeDelay = 75;

private int color;

private int minAlpha = 20;

//以下变量为自计算, 无需修改

private Paint mPaint;

private PointF center = new PointF(0,0);

private int alphaStep = 0;

private float angleStep = 0f;

private float baseAngle = 0f;

private float maxRadius = 0.0f;

private float minRadius = 0.0f;

private Timer timer;

private TimerTask timerTask = new TimerTask() {

@Override

public void run() {

float a = baseAngle - angleStep;

if (a % 360 == 0){

a = 0;

}

baseAngle = a;

postInvalidate();

}

};

public LoadingView(@NonNull Context context) {

this(context, null);

}

public LoadingView(@NonNull Context context, @Nullable AttributeSet attrs) {

this(context, attrs, 0);

}

public LoadingView(@NonNull Context context, @Nullable AttributeSet attrs, int defStyleAttr) {

super(context, attrs, defStyleAttr);

TypedArray attributes = context.obtainStyledAttributes(attrs, R.styleable.LoadingView);

initAttrs(attributes);

mPaint = new Paint(Paint.ANTI_ALIAS_FLAG);

mPaint.setDither(true);

mPaint.setStrokeWidth(strokeWidth);

mPaint.setStyle(Paint.Style.STROKE);

mPaint.setStrokeJoin(Paint.Join.ROUND);

mPaint.setStrokeCap(Paint.Cap.ROUND);

mPaint.setColor(color);

alphaStep = (0xff-minAlpha)/num;

angleStep = -360.0f/num;

timer = new Timer(false);

timer.schedule(timerTask,0, changeDelay);

setWillNotDraw(false);

}

private void initAttrs(TypedArray attributes) {

minAlpha = attributes.getInt(R.styleable.LoadingView_minAlpha,0x11);

changeDelay = attributes.getInt(R.styleable.LoadingView_runDuration,75);

num = attributes.getInt(R.styleable.LoadingView_lineCount,12);

strokeWidth = attributes.getDimension(R.styleable.LoadingView_lineWidth,5);

color = attributes.getColor(R.styleable.LoadingView_lineColor,Color.parseColor("#555555"));

}

@Override

protected void onAttachedToWindow() {

super.onAttachedToWindow();

}

@Override

protected void onDetachedFromWindow() {

timerTask.cancel();

timer.cancel();

super.onDetachedFromWindow();

}

@Override

protected void onLayout(boolean changed, int left, int top, int right, int bottom) {

super.onLayout(changed, left, top, right, bottom);

if (changed){

center.x = getWidth()/2.0f;

center.y = getHeight()/2.0f;

maxRadius = Math.min(getWidth(),getHeight())/2 - strokeWidth - 5;

minRadius = maxRadius/1.75f;

}

}

@Override

protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {

int desiredWidth = 80;

int desiredHeight = 80;

int widthMode = MeasureSpec.getMode(widthMeasureSpec);

int widthSize = MeasureSpec.getSize(widthMeasureSpec);

int heightMode = MeasureSpec.getMode(heightMeasureSpec);

int heightSize = MeasureSpec.getSize(heightMeasureSpec);

int width;

int height;

if (widthMode == MeasureSpec.EXACTLY) {

width = widthSize;

} else if (widthMode == MeasureSpec.AT_MOST) {

width = Math.min(desiredWidth, widthSize);

} else {

width = desiredWidth;

}

if (heightMode == MeasureSpec.EXACTLY) {

height = heightSize;

} else if (heightMode == MeasureSpec.AT_MOST) {

height = Math.min(desiredHeight, heightSize);

} else {

height = desiredHeight;

}

setMeasuredDimension(width, height);

center.x = getWidth()/2.0f;

center.y = getWidth()/2.0f;

maxRadius = Math.min(getWidth(),getHeight())/2 - strokeWidth - 5;

minRadius = maxRadius/1.75f;

}

@Override

public void draw(Canvas canvas) {

super.draw(canvas);

double a;

float x1,y1,x2,y2;

for (int i = 0; i < num; i++) {

a = angleStep * i + baseAngle;

x1 = (float) (Math.cos(Math.PI*a/180.0) * minRadius);

x2 = (float) (Math.cos(Math.PI*a/180.0) * maxRadius);

y1 = (float) (Math.sin(Math.PI*a/180.0) * minRadius);

y2 = (float) (Math.sin(Math.PI*a/180.0) * maxRadius);

Path path = new Path();

path.moveTo(center.x+x1,center.y+y1);

path.lineTo(center.x+x2,center.y+y2);

int alpha = 0xff - (i * alphaStep);

mPaint.setAlpha(alpha);

canvas.drawPath(path,mPaint);

}

}

}

styleable

作者言

喜欢请收藏点赞 ❤️

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Android仿iOS桌面应用删除动画可以使用属性动画实现。以下是一个简单的实现步骤: 1. 创建一个布局文件,用于显示要删除的应用图标。在这个布局中,你可以使用ImageView来显示应用图标,然后添一个TextView来显示删除提示。 2. 在Java代码中,使用属性动画设置ImageView的透明度和缩放比例。通过逐渐降低透明度和缩放比例,可以创建一个逐渐消失的效果。 3. 在动画结束时,删除应用程序,并在屏幕上显示一个Snackbar或Toast,以显示已删除的应用程序名称。 下面是一个示例代码,可以让你更好地了解如何实现这个功能: ```java public class DeleteAnimationActivity extends AppCompatActivity { private ImageView mAppIcon; private TextView mDeleteHint; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_delete_animation); mAppIcon = findViewById(R.id.iv_app_icon); mDeleteHint = findViewById(R.id.tv_delete_hint); // 设置属性动画 ObjectAnimator alphaAnimator = ObjectAnimator.ofFloat(mAppIcon, "alpha", 1f, 0f); ObjectAnimator scaleXAnimator = ObjectAnimator.ofFloat(mAppIcon, "scaleX", 1f, 0f); ObjectAnimator scaleYAnimator = ObjectAnimator.ofFloat(mAppIcon, "scaleY", 1f, 0f); // 设置动画集合 AnimatorSet animatorSet = new AnimatorSet(); animatorSet.playTogether(alphaAnimator, scaleXAnimator, scaleYAnimator); animatorSet.setDuration(500); // 监听动画结束事件 animatorSet.addListener(new AnimatorListenerAdapter() { @Override public void onAnimationEnd(Animator animation) { // 删除应用程序 deleteApp(); // 显示Snackbar或Toast Snackbar.make(mAppIcon, "已删除应用程序", Snackbar.LENGTH_LONG).show(); } }); // 启动动画 animatorSet.start(); } private void deleteApp() { // 删除应用程序的代码 } } ``` 在上面的代码中,我们使用 ObjectAnimator 来设置透明度和缩放比例的动画,然后使用 AnimatorSet 将它们组合在一起。在动画结束时,我们删除应用程序并显示一个Snackbar或Toast。 如果你想要更复杂的删除动画效果,可以尝试使用 PathInterpolator 或自定义 Interpolator 来控制动画的速度和速度。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值