利用DashPathEffect画具有动画效果的矩形动态头像边框
来源:互联网 发布:中国机床 知乎 编辑:程序博客网 时间:2024/05/16 07:56
package com.example.demo;import android.R.integer;import android.content.Context;import android.graphics.Canvas;import android.graphics.Color;import android.graphics.DashPathEffect;import android.graphics.Paint;import android.graphics.Path;import android.graphics.PathEffect;import android.graphics.Paint.Style;import android.util.AttributeSet;import android.widget.ImageView;public class CustomView extends ImageView{//画笔private Paint linePaint;//路径效果private PathEffect pathEffect;//路径对象private Path mPath;private float phase;public CustomView(Context context, AttributeSet attrs, int defStyleAttr) {super(context, attrs, defStyleAttr);// TODO Auto-generated constructor stub} public CustomView(Context context, AttributeSet attrs) {super(context, attrs);// TODO Auto-generated constructor stublinePaint=new Paint();}public CustomView(Context context) {super(context);// TODO Auto-generated constructor stub}@Overrideprotected void onDraw(Canvas canvas) {super.onDraw(canvas);pathEffect=new DashPathEffect(new float[] { 10, 15, 20, 10 }, phase);linePaint.setAntiAlias(true);//设置抗锯齿linePaint.setColor(Color.RED);//画笔颜色linePaint.setStyle(Style.STROKE);//画笔样式linePaint.setStrokeWidth(2);//画笔宽度linePaint.setPathEffect(pathEffect);//路径动画mPath=new Path();mPath.moveTo(0, 0);//起点mPath.lineTo(getRight()-20, 0);mPath.lineTo(getRight()-20, getBottom()-20);mPath.lineTo(0, getBottom()-20);mPath.close();canvas.translate(10, 10); canvas.drawPath(mPath, linePaint);canvas.translate(10, 10); }public void setPhase(float phase){this.phase=phase; postInvalidate(); }}
MainActivity:public class MainActivity extends Activity {private CustomView customView;private float pahse; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); customView=(CustomView) findViewById(R.id.customView); handler.sendEmptyMessage(0); } Handler handler=new Handler(){ public void handleMessage(android.os.Message msg) { if(msg.what==0){ pahse+=1; customView.setPhase(pahse); handler.sendEmptyMessage(0); } }; }; }
布局:<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" tools:context=".MainActivity" > <com.example.demo.CustomView android:id="@+id/customView" android:layout_width="200dp" android:layout_height="200dp" android:src="@drawable/ic_launcher" android:background="#ffff00" /></RelativeLayout>
0 0
- 利用DashPathEffect画具有动画效果的矩形动态头像边框
- 利用属性动画实现动态菜单的效果
- cocos2d-x 画一个有边框的矩形
- 实现类似于Vowch的头像移动的动画效果。
- android动画:头像在两个界面的移动效果
- DashPathEffect
- 利用铁匠组件实现在线头像截图的效果
- 带边框的圆形头像
- SVG实现边框动画效果
- Canvas实现矩形随机铺满的动画效果
- CALayer的使用(圆形头像 锚点 边框 阴影 形变 隐式动画 )
- ASP.net 使用(动态的有动画效果的)生成图表工具 Fusion Charts
- 利用 SVG 和 CSS3 实现有趣的边框动画
- 设置nv12的矩形边框
- 使用DashPathEffect绘制一条动画曲线
- 利用 CollapsingToolbarLayout 完成联动的动画效果
- Android 有点击动画效果的View
- Android利用CircleImageView实现圆形头像效果
- LeetCode 题解(248) : Encode and Decode Strings
- 黑马程序员—java API:集合框架 & 其他
- [LeetCode 287] Find the Duplicate Number
- jquery中attr和prop的区别
- xib中设置TableView的HeaderView
- 利用DashPathEffect画具有动画效果的矩形动态头像边框
- Java动态代理的实现机制
- 希望能被相关人看到,在百度知道 的提问被强奸了!
- my resume
- 利用dom4j读取完整的xml文档
- “钱三篇”后续之利息-钱的时间价值!
- Java Web读取properties配置文件
- scheme的应用序
- Java并发编程:CountDownLatch、CyclicBarrier和Semaphore