第二篇 根据识别的结果 我们可以访问一些网络 先写一个水波纹UI
来源:互联网 发布:cf手游雷神和无影数据 编辑:程序博客网 时间:2024/05/22 03:13
<com.example.admin.tim.UI.FingerWaveView android:id="@+id/view_custom" android:layout_width="140dp" android:layout_height="140dp" android:layout_centerInParent="true" /><ImageView android:id="@+id/iv" android:layout_width="60dp" android:layout_height="60dp" android:layout_centerInParent="true" android:src="@mipmap/ic_finger_status" /><TextView android:layout_centerHorizontal="true" android:layout_marginTop="20dp" android:id="@+id/tv_finger_status" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/iv" android:text="我是个可爱的麦克风" android:textColor="#fd7a72"android:textSize="12sp" />
当然ImageView的图片可以自定义
public class FingerWaveView extends View { private ImageView image; private TextView textView; private View view; private int start; private Paint mPaint; // 中心点x 坐标, 和 Y 坐标 private int mCenterX; private int mCenterY; // 开始绘制的圆的半径 : 默认 183dp private int mStartRadius; // 结束绘制的圆的半径 private int mEndRadius; // 动画执行的时间 private final long mDuration = 1000; // 变化时的圆的半径, 这个是变值... private int mCurrentRadius; // 圆环的半径, = 最大圆的半径 - 最小圆的半径(开始是的半径) private int mDurationWidth; private final int mStartAlpha = 100; private ValueAnimator mValueAnimator; public viewChangeListener viewChangeListener=new viewChangeListener() { @Override public void viewStart() { mStartRadius=start; view.setVisibility(VISIBLE); start(); } @Override public void viewEnd() { stop(); view.setVisibility(GONE); } }; public FingerWaveView(Context context, @Nullable AttributeSet attrs) { super(context, attrs); TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.FingerCaveImageView); mStartRadius = (int)(ta.getDimension(R.styleable.FingerCaveImageView_cave_radius,-1f)+0.5f); start=mStartRadius; init(); } // 初始化操作... private void init() { mPaint = new Paint(); mPaint.setColor(ContextCompat.getColor(getContext(), R.color.wave_color)); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.SRC_OVER)); // 设置锯齿 mPaint.setAntiAlias(true); // 创建一个属性动画, 从0 过度到 1 mValueAnimator = ValueAnimator.ofFloat(0, 1.0f); // 设置时长 mValueAnimator.setDuration(mDuration); // 重复次数为无限... mValueAnimator.setRepeatCount(ValueAnimator.INFINITE); // 线性插值器 mValueAnimator.setInterpolator(new LinearInterpolator()); //初始化 image=(ImageView)findViewById(R.id.iv); textView=(TextView)findViewById(R.id.tv_finger_status); // 监听过程, 在过程中处理参数变化 mValueAnimator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() { @Override public void onAnimationUpdate(ValueAnimator valueAnimator) { float value = (float) valueAnimator.getAnimatedValue(); mCurrentRadius = (int) (mStartRadius + mDurationWidth * value + 0.5); // 开始重新绘制 postInvalidate(); } }); view=(View)findViewById(R.id.view_custom); view.setVisibility(GONE); ((MainActivity)getContext()).getListener(viewChangeListener); } @Override protected void onFinishInflate() { super.onFinishInflate(); } @Override protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) { super.onMeasure(widthMeasureSpec, heightMeasureSpec); mCenterX = getMeasuredWidth() / 2; mCenterY = getMeasuredHeight() / 2; // 结束 绘制圆的半径为控件总宽度 高度, 的一般 mEndRadius = Math.min(getMeasuredWidth(), getMeasuredHeight()) / 2; mDurationWidth = mEndRadius - mStartRadius; } @Override protected void onDraw(Canvas canvas) { // 绘制第一个圆 int secondRadius = mCurrentRadius + (int) (mDurationWidth / 2.0f + 0.5f); if (secondRadius > mEndRadius) { secondRadius = mStartRadius + secondRadius - mEndRadius; } int secondAlpha = (int) (mStartAlpha * (1 - (secondRadius - mStartRadius) * 1.0f / mDurationWidth) + 0.5); mPaint.setAlpha(secondAlpha); canvas.drawCircle(mCenterX, mCenterY, secondRadius, mPaint); // 绘制第三个圆 int thirdRadius = mCurrentRadius + (int) (mDurationWidth / 2.0f * 2 + 0.5f); if (thirdRadius > mEndRadius) { thirdRadius = mStartRadius + thirdRadius - mEndRadius; } int thirdAlpha = (int) (mStartAlpha * (1 - (thirdRadius - mStartRadius) * 1.0f / mDurationWidth) + 0.5); mPaint.setAlpha(thirdAlpha); canvas.drawCircle(mCenterX, mCenterY, thirdRadius, mPaint); } public void stop() { mValueAnimator.end(); } public void start() { mValueAnimator.start(); }}关于Listener在MainActivity中
private com.example.admin.tim.interfacee.viewChangeListener viewChangeListener;public void getListener(viewChangeListener viewChangeListener){ this.viewChangeListener=viewChangeListener;}((MainActivity)getContext()).getListener(viewChangeListener);
阅读全文
0 0
- 第二篇 根据识别的结果 我们可以访问一些网络 先写一个水波纹UI
- 高级UI--有趣的水波纹
- 第二节 我们的网络
- 写了一个下载网络图片的功能,可以用
- 没钱的时候,我们可以先做好这些投资
- 【Unity】【Shader】写一个初步的水波模拟Gerstner Waves
- 一个C语言写的简单的单词识别程序附带VS性能分析结果
- jquery easy ui中根据第一个下拉框框选中的值,设置第二个下拉框是否可以编辑
- 先简单写一个,Linux下man命令使用的一些东东
- 根据CSDN网友的思路做的一个网络验证码识别控件
- 先写一个简单的例子
- 先写一个
- 周末闲着无聊分享一个自己写的带呼吸效果的android水波纹自定义view
- 一个可以筛选结果的下拉框
- 一个可以筛选结果的下拉框
- 一个可以识别人脸的Javascrpt
- 开平方 如果没有计算器,我们如何求2的平方根? 可以先猜测一个数,比如1.5,然后用2除以这个数字。
- 用Go写了一个可以用来访问goolge类似Proxy的小程序
- 解释器模式
- 浅谈对象池技术在游戏中的应用
- layout_weight让layout自动调整到剩余高度
- lua 错误处理
- istio 三日谈之一: 环境准备
- 第二篇 根据识别的结果 我们可以访问一些网络 先写一个水波纹UI
- 工作中常用到的Linux命令
- Python之基础知识(4. 字符操作)
- jquery中attr和prop的本质区别
- 无限极分类原理与实现
- 精通正则表达式:1 正则表达式入门
- CSS选择器的应用
- 购物车的 Adapter 删除条目的时候 会有BUG,解决办法
- 基于tiny4412的ts驱动简单分析