1. 程式人生 > >2022cma看片網站給一個你懂的

2022cma看片網站給一個你懂的

網站

看片網址 https://www.2022cma.com

自定義View_留聲機效果
(Values下)attrs.xml

[html] view plain copy
<?xml version="1.0" encoding="utf-8"?>
<resources>
<declare-styleable name="GramophoneView">
<attr name="picture_radiu" format="dimension"/> //中間圖片的半徑

<attr name="src" format="reference"/> //圖片
<attr name="disk_rotate_speed" format="float"/> //唱片旋轉的速度
</declare-styleable>
</resources>
自定義View

[java] view plain copy
public class GramophoneView extends View {

/** 
 * 尺寸計算設計說明: 
 * 1、唱片有兩個主要尺寸:中間圖片的半徑、黑色圓環的寬度。 
 * 黑色圓環的寬度 = 圖片半徑的一半。 
 * 2、唱針分為“手臂”和“頭”,手臂分兩段,一段長的一段短的,頭也是一段長的一段短的。 
 * 唱針四個部分的尺寸求和 = 唱片中間圖片的半徑+黑色圓環的寬度 
 * 唱針各部分長度 比例——長的手臂:短的手臂:長的頭:短的頭 = 8:4:2:1 
 * 3、唱片黑色圓環頂部到唱針頂端的距離 = 唱針長的手臂的長。度 
 */  

private final float DEFUALT_DISK_ROTATE_SPEED = 1f;      //磁盤旋轉的速度  
private final float DEFUALT_PICTURE_RAUID = 200;         //中間圖片默認半徑  
private final float DEFUALT_PAUSE_NEEDLE_DEGREE = -45;  //暫停狀態時唱針的旋轉角度  
private final float DEFUALT_PLAYING_NEEDLE_DEGREE = -15;     //播放狀態時唱針的旋轉角度  

private int pictrueRadio;   //中間圖片的半徑  

//指針  
private int smallCircleRadiu = 10;  //唱針頂部小圓半徑,減小了一半  
private int bigCircleRadiu = 15;    //唱針頂部大圓半徑,減小了一半  

private int shortArmLength;  
private int longArmleLength;         // 唱針手臂,較長那段的長度  
private int shortHeadLength;         // 唱針的頭,較短那段的長度  
private int longHeadLength;  
private Paint needlePaint;  

//唱片  
private float halfMeasureWidth;  
private int diskRingWidth;            // 黑色圓環寬度  
private float diskRotateSpeed;        // 唱片旋轉速度  
private Bitmap pictureBitmap;  
private Paint diskPaint;  

//狀態控制  
private boolean isPlaying;  
private float currentDiskDegree;            // 唱片旋轉角度  
private float currentNeddleDegree = DEFUALT_PLAYING_NEEDLE_DEGREE;  // 唱針旋轉角度  

public GramophoneView(Context context) {  
    this(context,null);  
}  

public GramophoneView(Context context, @Nullable AttributeSet attrs) {  
    super(context, attrs);  
    needlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);//抗鋸齒  
    diskPaint = new Paint(Paint.ANTI_ALIAS_FLAG);  
    TypedArray typedArray = getContext().obtainStyledAttributes(attrs, R.styleable.GramophoneView);  

// 拿到xml中的圖片和圖片半徑和,旋轉的度數
pictrueRadio = (int) typedArray.getDimension(R.styleable.GramophoneView_picture_radiu, DEFUALT_PICTURE_RAUID);
diskRotateSpeed = typedArray.getFloat(R.styleable.GramophoneView_disk_rotate_speed, DEFUALT_DISK_ROTATE_SPEED);
Drawable drawable = typedArray.getDrawable(R.styleable.GramophoneView_src);

if (drawable == null) {
pictureBitmap = BitmapFactory.decodeResource(getResources(), R.mipmap.ic_launcher);
} else {
pictureBitmap = ((BitmapDrawable)drawable).getBitmap();
}

    //初始化唱片的變量  
    diskRingWidth = pictrueRadio >> 1;  

    shortHeadLength = (pictrueRadio + diskRingWidth) / 15;    //圖片半徑和黑色圓環的和 等於 指針的總長度  
    longHeadLength = shortHeadLength << 1;    //左移相當於乘以2  
    shortArmLength = longHeadLength << 1;  
    longArmleLength = shortArmLength << 1;  
}  

/** 
 * 理想的寬高是,取決於picture的 半徑的 
 * 
 * @param widthMeasureSpec 
 * @param heightMeasureSpec 
 */  
@Override  
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {  
    super.onMeasure(widthMeasureSpec, heightMeasureSpec);  
    //我們想要的理想寬高  
    int width = (pictrueRadio+diskRingWidth)*2;  
    int hight = (pictrueRadio+diskRingWidth)*2+longArmleLength;  

2022cma看片網站給一個你懂的