最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Android自定義圓形進(jìn)度條效果

 更新時(shí)間:2021年04月19日 09:52:10   作者:dongxiaogang5_5  
這篇文章主要為大家詳細(xì)介紹了Android自定義圓形進(jìn)度條效果,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了Android自定義圓形進(jìn)度條效果的具體代碼,供大家參考,具體內(nèi)容如下

1 控件 RoundProgress

package listview.tianhetbm.p2p.ui;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

import listview.tianhetbm.p2p.R;

/**
 * @date:2015/9/14
 * @author:dongxiaogang
 * @description: 自定義圓形進(jìn)度條
 */
public class RoundProgress extends View {
    private Paint paint = new Paint();

    private int roundColor;
    private int roundProgressColor;
    private int textColor;
    private float textSize;
    private float roundWidth;
    private int max = 100;

    private int progress = 50;

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

    public RoundProgress(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RoundProgress(Context context, AttributeSet attrs, int defStyleAttr) {
        super(context, attrs, defStyleAttr);
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.RoundProgress);
        //圓環(huán)的顏色
        roundColor = ta.getColor(R.styleable.RoundProgress_roundColor, Color.RED);
        //圓環(huán)進(jìn)度的顏色
        roundProgressColor = ta.getColor(R.styleable.RoundProgress_roundProgressColor, Color.GREEN);
        //中間進(jìn)度百分比文字字符串的顏色
        textColor = ta.getColor(R.styleable.RoundProgress_textColor, Color.GREEN);
        //中間進(jìn)度百分比的字符串的字體大小
        textSize = ta.getDimension(R.styleable.RoundProgress_textSize, 15);
        //圓環(huán)的寬度
        roundWidth = ta.getDimension(R.styleable.RoundProgress_roundWidth, 5);
        ta.recycle();
    }

    @Override
    protected void onDraw(Canvas canvas) {
//第一步:繪制一個(gè)最外層的圓
        paint.setColor(roundColor);
        paint.setStrokeWidth(roundWidth);
        paint.setStyle(Paint.Style.STROKE);
        paint.setAntiAlias(true);
        int center = getWidth() / 2;
        int radius = (int) (center - roundWidth / 2-45);
        //canvas.drawCircle(center, center, radius, paint);
        RectF oval = new RectF(center - radius, center - radius, center + radius, center + radius);
        canvas.drawArc(oval, 135, 270, false, paint);
        //第二步:繪制正中間的文本
        float textWidth = paint.measureText(progress + "%");
        paint.setColor(textColor);
        paint.setTextSize(textSize);
        paint.setStrokeWidth(0);
        canvas.drawText(progress + "%", center - textWidth / 2, center + textSize / 2, paint);

        //第三步:
        /**
         * 參數(shù)解釋?zhuān)?
         * oval:繪制弧形圈所包含的矩形范圍輪廓
         * 0:開(kāi)始的角度
         * 360 * progress / max:掃描過(guò)的角度
         * false:是否包含圓心
         * paint:繪制弧形時(shí)候的畫(huà)筆
         */
        //RectF oval = new RectF(center - radius, center - radius, center + radius, center + radius);
        paint.setColor(roundProgressColor);
        paint.setStrokeWidth(roundWidth);
        paint.setStyle(Paint.Style.STROKE);
        canvas.drawArc(oval, 135, 270 * progress / max, false, paint);
        Log.e("測(cè)試角度",(270 * progress / max)+"");

        Paint mp=new Paint();
        mp.setAntiAlias(true);
        Bitmap bitmap= BitmapFactory.decodeResource(getResources(),R.drawable.tiger);
        int bitmapHeight = bitmap.getHeight()/2;
        int bitmapWidth = bitmap.getWidth()/2;
        //canvas.translate(-center, center);
        float y=0f,x=0f;
//        if(270 * progress / max<=45){
            y = (float) (center-bitmapWidth - (radius) * Math.cos((270 * progress / max+225)*Math.PI/180));
            x = (float) (center-bitmapWidth + (radius) * Math.sin((270 * progress / max+225)*Math.PI/180));
//        }
    //canvas.translate(center, center*2);
    Log.e("測(cè)試角度", y + "-----" + x);
    canvas.drawBitmap(bitmap, x, y, mp);


    }
    public void setProgress(int progress){
        this.progress = progress;
        if(progress>100){
            this.progress = 100;
        }
        postInvalidate();
    }
}

2 xml 布局文件

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:gravity="center_horizontal">
    <listview.tianhetbm.p2p.ui.RoundProgress

        android:layout_marginTop="30dp"
        android:layout_width="250dp"
        android:layout_height="250dp"
        android:layout_marginLeft="10dp"
        app:roundColor="@color/back_blue"
        app:roundProgressColor="@color/back_orange"
        android:id="@+id/ce"
        app:roundWidth="10dp"
        app:textSize="18sp"
        app:textColor="@color/record_red"
        />
</RelativeLayout>

3 activity(主要代碼)

 super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main_three);
        ButterKnife.bind(this);
        new Thread(){
           @Override
           public void run() {
               while (progress<80){
                   progress+=1;
                   ce.setProgress(progress);
                   try {
                       Thread.sleep(50);
                   } catch (Exception e) {
                       e.printStackTrace();
                   }

               }
           }
}.start();

以上就是本文的全部?jī)?nèi)容,希望對(duì)大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

  • Android開(kāi)發(fā)筆記之Android中數(shù)據(jù)的存儲(chǔ)方式(二)

    Android開(kāi)發(fā)筆記之Android中數(shù)據(jù)的存儲(chǔ)方式(二)

    我們?cè)趯?shí)際開(kāi)發(fā)中,有的時(shí)候需要儲(chǔ)存或者備份比較復(fù)雜的數(shù)據(jù)。這些數(shù)據(jù)的特點(diǎn)是,內(nèi)容多、結(jié)構(gòu)大,比如短信備份等,通過(guò)本文給大家介紹Android開(kāi)發(fā)筆記之Android中數(shù)據(jù)的存儲(chǔ)方式(二),對(duì)android數(shù)據(jù)存儲(chǔ)方式相關(guān)知識(shí)感興趣的朋友一起學(xué)習(xí)吧
    2016-01-01
  • Android?Studio中使用SQLite數(shù)據(jù)庫(kù)實(shí)現(xiàn)登錄和注冊(cè)功能

    Android?Studio中使用SQLite數(shù)據(jù)庫(kù)實(shí)現(xiàn)登錄和注冊(cè)功能

    SQLite是一款輕型的數(shù)據(jù)庫(kù),是遵守ACID的關(guān)系型數(shù)據(jù)庫(kù)管理系統(tǒng),它包含在一個(gè)相對(duì)小的C庫(kù)中,下面這篇文章主要給大家介紹了關(guān)于Android?Studio中使用SQLite數(shù)據(jù)庫(kù)實(shí)現(xiàn)登錄和注冊(cè)功能的相關(guān)資料,需要的朋友可以參考下
    2024-06-06
  • 完美解決安卓jni項(xiàng)目會(huì)刪除其他so文件的問(wèn)題

    完美解決安卓jni項(xiàng)目會(huì)刪除其他so文件的問(wèn)題

    下面小編就為大家?guī)?lái)一篇完美解決安卓jni項(xiàng)目會(huì)刪除其他so文件的問(wèn)題。小編覺(jué)得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2016-12-12
  • Android開(kāi)發(fā)Compose集成高德地圖實(shí)例

    Android開(kāi)發(fā)Compose集成高德地圖實(shí)例

    這篇文章主要為大家介紹了Android開(kāi)發(fā)Compose里使用高德地圖實(shí)例詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2022-08-08
  • Android圖文居中顯示控件使用方法詳解

    Android圖文居中顯示控件使用方法詳解

    這篇文章主要為大家詳細(xì)介紹了Android圖文居中顯示控件的使用方法,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2020-09-09
  • Android SharedPreferences的使用分析

    Android SharedPreferences的使用分析

    本篇文章小編為大家介紹,Android SharedPreferences的使用分析。需要的朋友參考下
    2013-04-04
  • 詳解Android Studio Git分支實(shí)踐

    詳解Android Studio Git分支實(shí)踐

    這篇文章主要介紹了Android Studio Git分支實(shí)踐,小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,也給大家做個(gè)參考。一起跟隨小編過(guò)來(lái)看看吧
    2018-05-05
  • Android基礎(chǔ)之Activity生命周期

    Android基礎(chǔ)之Activity生命周期

    activity類(lèi)是Android 應(yīng)用生命周期的重要部分。在系統(tǒng)中的Activity被一個(gè)Activity棧所管理。當(dāng)一個(gè)新的Activity啟動(dòng)時(shí),將被放置到棧頂,成為運(yùn)行中的Activity,前一個(gè)Activity保留在棧中,不再放到前臺(tái),直到新的Activity退出為止。
    2016-05-05
  • Android EditText被軟鍵盤(pán)遮蓋的處理方法

    Android EditText被軟鍵盤(pán)遮蓋的處理方法

    android app新增了透明欄效果,結(jié)果發(fā)現(xiàn)鍵盤(pán)彈起后會(huì)遮蓋屏幕底部的EditText,沒(méi)有像想象中的調(diào)整窗口大小,并滾動(dòng)ScrollView,將EditText顯示在鍵盤(pán)上方。下面小編把解決方法記錄一下,特此分享到腳本之家平臺(tái),感興趣的朋友一起看看吧
    2016-10-10
  • Android編程之selector下設(shè)置背景屬性值的方法

    Android編程之selector下設(shè)置背景屬性值的方法

    這篇文章主要介紹了Android編程之selector下設(shè)置背景屬性值的方法,結(jié)合實(shí)例形式分析了Android的selector背景選擇器相關(guān)使用技巧,需要的朋友可以參考下
    2016-01-01

最新評(píng)論

那曲县| 南岸区| 荃湾区| 石嘴山市| 柞水县| 凤台县| 聂荣县| 拉孜县| 建宁县| 英德市| 措美县| 西城区| 玉龙| 南木林县| 巫溪县| 阿尔山市| 开原市| 北宁市| 县级市| 榆中县| 丰台区| 克拉玛依市| 松江区| 聂拉木县| 沁源县| 米脂县| 凤冈县| 沈阳市| 卓资县| 阳朔县| 教育| 彰化县| 麻江县| 龙山县| 太谷县| 阳泉市| 宁蒗| 仁寿县| 防城港市| 广河县| 苏尼特右旗|