zoukankan      html  css  js  c++  java
  • android测试Code

    <!--android:layout_alignParentTop="true"-->
    <com.koooke.platform.View.CenterImage
    android:id="@+id/centerImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_alignParentEnd="true"
    android:layout_gravity="center_horizontal"
    android:layout_marginEnd="154dp"
    android:scaleType="centerCrop"
    android:src="@drawable/koookelogo" />
    package com.koooke.platform.View;

    import android.animation.ValueAnimator;
    import android.content.Context;
    import android.graphics.Bitmap;
    import android.graphics.BitmapFactory;
    import android.graphics.Canvas;
    import android.graphics.Color;
    import android.graphics.Paint;
    import android.util.AttributeSet;
    import android.view.animation.LinearInterpolator;

    import com.koooke.platform.R;


    /**
    * Created by Uniway_125 on 2017/11/27 0027.
    */

    public class CenterImage extends android.support.v7.widget.AppCompatImageView {
    private Paint paint;
    private boolean isCenterImgShow;
    private Bitmap bitmap;
    public void setCenterImgShow(boolean centerImgShow) {
    isCenterImgShow = centerImgShow;
    if (isCenterImgShow) {
    bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    invalidate();
    }
    bitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
    }
    public CenterImage(Context context) {
    super(context);
    init();
    }
    public CenterImage(Context context, AttributeSet attrs) {
    super(context, attrs);
    init();
    }
    public CenterImage(Context context, AttributeSet attrs, int defStyleAttr) {
    super(context, attrs, defStyleAttr);
    init();
    }
    private void init() {
    paint = new Paint();
    isDrawPoint = true;
    }
    private boolean isInit = false;


    private ValueAnimator animator;

    /********
    * 计算圆弧点上的坐标
    * 公式:Math.sin(x) x 的正玄值。返回值在 -1.0 到 1.0 之间;
    * Math.cos(x) x 的余弦值。返回的是 -1.0 到 1.0 之间的数;
    * <p>
    * X指的是弧度 因此
    * <p>
    * 30° 角度 的弧度 = 2*PI/360*30
    * <p>
    * 圆上每个点的X坐标=a + Math.sin(2*Math.PI / 360) * r
    * Y坐标=b + Math.cos(2*Math.PI / 360) * r ;
    **************/
    private boolean isDrawPoint = false;
    public void setDrawPoint(boolean drawPoint) {
    isDrawPoint = drawPoint;
    }
    // @Override
    // protected void onDraw(Canvas canvas) {
    // super.onDraw(canvas);
    // if ( bitmap != null) {
    //
    // System.out.println(String.format("wight %d,height %d",getWidth(),getHeight()));
    // Paint paint2 = new Paint();
    // paint2.setStyle(Paint.Style.FILL);
    // paint2.setColor(Color.WHITE);
    // canvas.drawCircle( getMeasuredWidth()/2 , 3 ,smallBallWidth, paint2);
    // //canvas.drawBitmap(bitmap, getMeasuredWidth() / 2 +50, getMeasuredHeight(), paint);
    // Paint paint3 = new Paint();
    // paint3.setStyle(Paint.Style.FILL);
    // paint3.setColor(Color.WHITE);
    //
    // canvas.drawCircle( getMeasuredWidth()/2 , getMeasuredHeight()-3,smallBallWidth, paint3);
    // }
    // }
    @Override
    protected void onDraw(Canvas canvas) {
    super.onDraw(canvas);
    r = getMeasuredWidth()/2;
    Paint paint2 = new Paint();
    paint2.setStyle(Paint.Style.FILL);
    paint2.setColor(Color.WHITE);
    canvas.drawCircle( getMeasuredWidth()/2 , smallBallWidth ,smallBallWidth, paint2);

    //canvas.drawBitmap(bitmap, getMeasuredWidth() / 2 +50, getMeasuredHeight(), paint);
    Paint paint3 = new Paint();
    paint3.setStyle(Paint.Style.FILL);
    paint3.setColor(Color.WHITE);
    canvas.drawCircle( getMeasuredWidth()/2 , getMeasuredHeight()-smallBallWidth,smallBallWidth, paint3);


    }
    private void MathDisc(Canvas canvas,Paint inputPaint,float base ) { //angle 角度

    float hudu = (float) ((2 * Math.PI / 360) * (angle))+base; // 360/8=45,即45度(这个随个人设置)
    float X = (float) (r + smallBallWidth + Math.sin(hudu) * r); // r+5 是圆形中心的坐标X 即定位left 的值
    float Y = (float) (r + smallBallWidth - Math.cos(hudu) * r); // r+5 是圆形中心的坐标Y 即定位top 的值
    System.out.println(String.format("X = %f y = %f",X, Y));
    canvas.drawCircle(X, Y, smallBallWidth, inputPaint);
    canvas.restore();

    }
    private int r = 0;//半径
    private int smallBallWidth = 4;
    /********
    * 计算圆弧点上的坐标
    * 公式:Math.sin(x) x 的正玄值。返回值在 -1.0 到 1.0 之间;
    * Math.cos(x) x 的余弦值。返回的是 -1.0 到 1.0 之间的数;
    * <p>
    * X指的是弧度 因此
    * <p>
    * 30° 角度 的弧度 = 2*PI/360*30
    * <p>
    * 圆上每个点的X坐标=a + Math.sin(2*Math.PI / 360) * r
    * Y坐标=b + Math.cos(2*Math.PI / 360) * r ;
    **************/
    // private void MathDisc(Canvas canvas) { //angle 角度
    // if (isDrawPoint) {
    // float hudu = (float) ((2 * Math.PI / 360) * (angle)); // 360/8=45,即45度(这个随个人设置)
    // float X = (float) (r + 5 + Math.sin(hudu) * r); // r+5 是圆形中心的坐标X 即定位left 的值
    // float Y = (float) (r + 5 - Math.cos(hudu) * r); // r+5 是圆形中心的坐标Y 即定位top 的值
    // canvas.drawCircle(X, Y, smallBallWidth, circleRing);
    // canvas.restore();
    // }
    // }


    private float angle = 0;
    public void startAnimation() {
    animator = ValueAnimator.ofFloat(0, 1.0f);
    //动画时长,让进度条在CountDown时间内正好从0-360走完,
    animator.setDuration(1000);
    animator.setInterpolator(new LinearInterpolator());//匀速
    animator.setRepeatCount(-1);//表示不循环,-1表示无限循环
    //值从0-1.0F 的动画,动画时长为countdownTime,ValueAnimator没有跟任何的控件相关联,那也正好说明ValueAnimator只是对值做动画运算,而不是针对控件的,我们需要监听ValueAnimator的动画过程来自己对控件做操作
    //添加监听器,监听动画过程中值的实时变化(animation.getAnimatedValue()得到的值就是0-1.0)
    animator.addUpdateListener(new ValueAnimator.AnimatorUpdateListener() {
    @Override
    public void onAnimationUpdate(ValueAnimator animation) {
    /**
    * 这里我们已经知道ValueAnimator只是对值做动画运算,而不是针对控件的,因为我们设置的区间值为0-1.0f
    * 所以animation.getAnimatedValue()得到的值也是在[0.0-1.0]区间,而我们在画进度条弧度时,设置的当前角度为360*currentAngle,
    * 因此,当我们的区间值变为1.0的时候弧度刚好转了360度
    */
    angle = 360 * (float) animation.getAnimatedValue();
    invalidate();//实时刷新view,这样我们的进度条弧度就动起来了
    }
    });
    //开启动画
    animator.start();
    }
    }
  • 相关阅读:
    HttpRunner学习3--extract提取数据和引用
    利用Fiddler对Jmeter的请求进行抓包
    HttpRunner学习2--用例格式和简单使用
    HttpRunner学习1--Windows&Linux安装httprunner
    Linux日志中如何查找关键字及其前后的信息
    Linux命令学习-cat命令
    Linux下安装MySQL 5.7
    阿里云服务器修改主机名
    Linux下设置mysql允许远程连接
    利用PyInstaller打包exe文件
  • 原文地址:https://www.cnblogs.com/wcLT/p/7905703.html
Copyright © 2011-2022 走看看