Andriodjie——画圆3秒跳转
来源:互联网 发布:数据分析平台页面设计 编辑:程序博客网 时间:2024/05/23 11:01
////欢迎页import android.animation.AnimatorSet;import android.animation.ObjectAnimator;import android.content.Intent;import android.os.AsyncTask;import android.os.Bundle;import android.os.Handler;import android.os.SystemClock;import android.support.v7.app.AppCompatActivity;import android.widget.ImageView;public class WelcomeActivity extends AppCompatActivity { private ImageView iv; private MyView myView; int time = 3; Handler handler = new Handler(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.welcome); initView(); initAnimator(); } private void initAnimator() { AnimatorSet set = new AnimatorSet(); float y = iv.getTranslationY(); ObjectAnimator objectAnimator = ObjectAnimator.ofFloat(iv,"translationY",y,450); objectAnimator.setDuration(3000); ObjectAnimator objectAnimator1 = ObjectAnimator.ofFloat(iv,"scaleY",1f,2f,1f); objectAnimator1.setDuration(3000); set.play(objectAnimator).before(objectAnimator1); set.start(); handler.postDelayed(new Runnable() { @Override public void run() { time--; if(time == 0){ Intent intent = new Intent(WelcomeActivity.this, MainActivity.class); startActivity(intent); finish(); } handler.postDelayed(this,1000); } },3000); new AsyncTask<String,Integer,String>(){ @Override protected String doInBackground(String... strings) { for (int i = 1; i <=4 ; i++) { SystemClock.sleep(1000); publishProgress(i); } return null; } @Override protected void onProgressUpdate(Integer... values) { myView.setProgress(values[0]); } }.execute(); } private void initView() { iv = (ImageView) findViewById(R.id.welcome_iv); myView = (MyView) findViewById(R.id.myView); } @Override protected void onDestroy() { super.onDestroy(); }}
//编辑属性
import android.animation.ArgbEvaluator;import android.animation.ValueAnimator;import android.content.Context;import android.content.res.TypedArray;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.Paint;import android.graphics.RectF;import android.support.annotation.Nullable;import android.util.AttributeSet;import android.view.View;/** * */public class MyView extends View { private Paint paint; boolean flag = true; private int mProgress = 0; private int mCountProgress = 0; private float mRadiuSize = 0; private float mRingSize = 0; private float mTextSize = 0; private int mProgressColor = 0; private int currentColor; private ValueAnimator animator; public MyView(Context context) { super(context); init(); } private void init() { paint = new Paint(); paint.setAntiAlias(true); } public MyView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); getCustomAttr(context, attrs); init();} public MyView(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); getCustomAttr(context, attrs); init(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); int widthMode = MeasureSpec.getMode(widthMeasureSpec); int widthSize = MeasureSpec.getSize(widthMeasureSpec); int heightMode = MeasureSpec.getMode(heightMeasureSpec); int heightSize = MeasureSpec.getSize(heightMeasureSpec); int width = 0; int height = 0; if (widthMode == MeasureSpec.AT_MOST) { width = (int) (mRadiuSize * 2); } else { width = Math.max(widthSize, (int) (mRadiuSize * 2)); } if (heightMode == MeasureSpec.AT_MOST) { height = (int) (mRadiuSize * 2); } else { height = Math.max(heightSize, (int) (mRadiuSize * 2)); } setMeasuredDimension(width, height); } private void getCustomAttr(Context context, AttributeSet attrs) { TypedArray array = context.obtainStyledAttributes(attrs, R.styleable.MyView); mRadiuSize = array.getDimension(R.styleable.MyView_radiuSize, 100); mRingSize = array.getDimension(R.styleable.MyView_ringSize, 10); mTextSize = array.getDimension(R.styleable.MyView_textSize, 10); mProgressColor = array.getColor(R.styleable.MyView_progressColor, currentColor); } @Override protected void onDraw(Canvas canvas) { animator = ValueAnimator.ofObject(new ArgbEvaluator(), Color.RED, Color.BLUE); animator.setDuration(500); animator.setRepeatCount(ValueAnimator.INFINITE); animator.setRepeatMode(ValueAnimator.REVERSE); animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { currentColor = (int) valueAnimator.getAnimatedValue(); } }); paint.setStrokeWidth(0); paint.setColor(Color.BLACK); paint.setStyle(Paint.Style.STROKE); canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, mRadiuSize, paint); canvas.drawCircle(getMeasuredWidth() / 2, getMeasuredHeight() / 2, mRadiuSize - mRingSize, paint); paint.setTextSize(mTextSize); String text = mCountProgress+""; float textWidth = paint.measureText(text); canvas.drawText(text, getMeasuredWidth() / 2 - textWidth / 2, getMeasuredWidth() / 2 + mTextSize / 2, paint); RectF rectF = new RectF(getMeasuredWidth() / 2 - mRadiuSize + mRingSize / 2, getMeasuredHeight() / 2 - mRadiuSize + mRingSize / 2, getMeasuredWidth() / 2 + mRadiuSize - mRingSize / 2, getMeasuredHeight() / 2 + mRadiuSize - mRingSize / 2); paint.setStrokeWidth(mRingSize); paint.setColor(currentColor); canvas.drawArc(rectF, 0, mProgress*90, false, paint); } public void setProgress(int progress) { if (flag) { animator.start(); flag = false; } mProgress = (4-progress); mCountProgress = (4-progress) ; invalidate(); }}attrs.xml
<?xml version="1.0" encoding="utf-8"?><resources> <declare-styleable name="MyView"> <attr name="progressColor" format="color"/> <attr name="textSize" format="dimension"/> <attr name="ringSize" format="dimension"/> <attr name="radiuSize" format="dimension"/> </declare-styleable></resources>//清单文件
<?xml version="1.0" encoding="utf-8"?><manifest xmlns:android="http://schemas.android.com/apk/res/android" package="com.example.tuhua"> <uses-permission android:name="android.permission.INTERNET"/> <uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/> <application android:allowBackup="true" android:icon="@mipmap/ic_launcher" android:label="@string/app_name" android:supportsRtl="true" android:theme="@style/AppTheme"> <activity android:name=".WelcomeActivity"> <intent-filter> <action android:name="android.intent.action.MAIN" /> <category android:name="android.intent.category.LAUNCHER" /> </intent-filter> </activity> <activity android:name=".MainActivity"></activity> </application></manifest>
阅读全文
0 0
- Andriodjie——画圆3秒跳转
- Andriodjie——欢迎页3秒跳转到主页+banner图片轮播
- andriodjie——recycleview
- andriodjie——mvp展示拦截器传来的数据跳转购物车
- Andriodjie——登陆注册展示商品
- Andriodjie——OKhttp拦截器
- Andriodjie——自定义头布局
- andriodjie——实现小圆点
- Andriodjie——RecyclerView点击查看商品详情
- Andriodjie——简单的购物车全选反选
- Andriodjie——二级列表实现购物车
- andriodjie——MVP加RecycleView简单展示
- andriodjie——xRecyclerView网络获取数据简单实现
- Andriodjie——二级列表实现购物车
- 3秒后跳转
- 3秒跳转
- Handler 3秒跳转
- 3秒跳转事件
- Oracle12C--对象视图(67)
- 对象可见性规则[java7高级进阶]
- redis相关知识
- python学习之路--numbers
- 633. Sum of Square Numbers (数学)
- Andriodjie——画圆3秒跳转
- App架构经验总结
- 实验5
- django虚拟环境创建
- 类的六个默认成员函数(转)
- Oracle之聚合因子
- 18.jdbc技术
- 数据库事物
- useful libs for python