圆环加属性动画
来源:互联网 发布:网络用语小白什么意思 编辑:程序博客网 时间:2024/05/29 09:15
//布局<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:app="http://schemas.android.com/apk/res-auto" tools:context="test.bwei.com.zhoukao1009.MainActivity"> <test.bwei.com.zhoukao1009.MyRound android:id="@+id/mpr" android:layout_width="wrap_content" android:layout_height="wrap_content" app:ringSize="10dp" app:progressColor="#883399" app:radiuSize="150dp" app:textSize="20sp" /> <Button android:id="@+id/begin" android:layout_alignParentBottom="true" android:layout_width="wrap_content" android:layout_alignParentLeft="true" android:text="开始" android:textSize="25sp" android:layout_height="50dp" /> <Button android:id="@+id/resut" android:layout_alignParentBottom="true" android:layout_width="wrap_content" android:textSize="25sp" android:layout_alignParentRight="true" android:text="重置" android:layout_height="50dp" /></RelativeLayout>
// MyMainActivity
public class MainActivity extends AppCompatActivity { MyRound mpr; Button began,resut; boolean flag=false; Handler handler=new Handler(){ @Override public void handleMessage(Message msg) { super.handleMessage(msg); mpr.setmCountProgress(); } }; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); mpr= (MyRound) findViewById(R.id.mpr); began= (Button) findViewById(R.id.begin); resut= (Button) findViewById(R.id.resut); //左右移动 float x=mpr.getTranslationX(); ObjectAnimator animator=ObjectAnimator.ofFloat(mpr,"translationX",x,50,x); animator.setDuration(5000); //缩放 ObjectAnimator animator2=ObjectAnimator.ofFloat(mpr,"scaleY",1f,0.5f,2f,1f); animator2.setDuration(5000); AnimatorSet set=new AnimatorSet(); set.play(animator).after(animator2); set.start(); began.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { new AsyncTask<String,Integer,String>(){ @Override protected String doInBackground(String... strings) { flag=false; for (int i = 1; i < 361; i++) { if(flag) { handler.sendEmptyMessage(0); break; } SystemClock.sleep(10); publishProgress(i); } return null; } @Override protected void onProgressUpdate(Integer... values) { mpr.setmProgress(values[0]); } }.execute(); } }); resut.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View view) { flag=true; } }); }//MyRound
public class MyRound extends View { Paint paint; private int mProgress=0; private int mCountProgress=0; private float mRadiuSize=0; private float mRingSize=0; private float mTextSize=0; private int mProgressColor=0; public MyRound(Context context) { super(context); init(); } public MyRound(Context context, AttributeSet attrs) { super(context, attrs); getCustomAttr(context,attrs); init(); } private void getCustomAttr(Context context, AttributeSet attrs) { TypedArray array=context.obtainStyledAttributes(attrs,R.styleable.MyProgressRound); mRadiuSize=array.getDimension(R.styleable.MyProgressRound_radiuSize,100); mRingSize=array.getDimension(R.styleable.MyProgressRound_ringSize,10); mTextSize=array.getDimension(R.styleable.MyProgressRound_textSize,10); mProgressColor=array.getColor(R.styleable.MyProgressRound_progressColor,Color.BLACK); } public MyRound(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); init(); } public void init(){ paint=new Paint(); paint.setAntiAlias(true); paint.setTextSize(45); } @Override protected void onDraw(Canvas canvas) { paint.setStrokeWidth(0); paint.setColor(Color.GREEN); paint.setStyle(Paint.Style.STROKE); canvas.drawCircle(200,200,mRadiuSize,paint); canvas.drawCircle(200,200,mRadiuSize-mRingSize,paint); canvas.drawText(mCountProgress+"%",200,200,paint); RectF rectF=new RectF(200-mRadiuSize+mRingSize/2,200-mRadiuSize+mRingSize/2,200+mRadiuSize-mRingSize/2,200+mRadiuSize-mRingSize/2); paint.setStrokeWidth(mRingSize); canvas.drawArc(rectF,0,mProgress,false,paint); } public void setmProgress(int progress){ mProgress=progress; mCountProgress=progress*100/360; invalidate(); } public void setmCountProgress(){ mProgress=0; mCountProgress=0; invalidate(); }
阅读全文
0 0
- 圆环加属性动画
- 属性动画+圆环进度条
- android属性动画圆环+箭头
- 属性动画+自定义view进度圆环的倒计时
- 自定义view加属性动画
- Android自定义View和属性动画完美结合,创造出酷炫圆环动画,带标尺和进度
- ios 圆环加载动画
- css3圆环动画
- Animation介绍加动画属性的详解
- 自定义view实心圆加属性动画
- 自定义view圆加属性动画
- 属性动画的平移加旋转
- CleanMasterSecurity的圆环动画实现
- [IOS动画]KDProgressView(圆环)
- Loading动画--加载成功--圆环
- 圆环形TextView+旋转动画
- 自定义圆环进度条+自定义属性
- 带缺口的圆环CSS3 Loading动画
- linux 常用命令(2)
- Java面试题
- C#中的NVC框架
- hdu 5768
- linux各个目录作用
- 圆环加属性动画
- C++构建循环链表(无头节点)
- 树链剖分初步
- [微机原理]BCD码减法
- 判断是否为微信内置浏览器
- NKOJ训练赛 过路费(最短路)
- python pandas库详解
- Angular模板与表达式的绑定
- BZOJ1066: [SCOI2007]蜥蜴