欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

android自定義進(jìn)度條移動(dòng)效果

 更新時(shí)間:2021年05月31日 10:30:23   作者:liuye066  
這篇文章主要為大家詳細(xì)介紹了android自定義進(jìn)度條移動(dòng)效果,進(jìn)度數(shù)字隨進(jìn)度移動(dòng),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下

本文實(shí)例為大家分享了android實(shí)現(xiàn)進(jìn)度條移動(dòng)效果的具體代碼,供大家參考,具體內(nèi)容如下

自定義進(jìn)度條,效果如下:

CustomViewActivity.java

public class CustomViewActivity extends Activity {
    private static final String TAG = "CustomViewActivity";
    private TextView tv_schedule;
    private View view;
    private ProgressBar progressBar;
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_custom_view);
        initView();
    }
 
    private void initView() {
        initProgressView();
    }
 
    private void initProgressView() {
        tv_schedule = findViewById(R.id.tv_schedule);
        view = findViewById(R.id.view);
        progressBar = findViewById(R.id.progressbar);
        int finishSpeed = 2;
        Log.d(TAG,"finishSpeed="+finishSpeed);
        float speedPer = ((float) finishSpeed)/8*100;
        Log.d(TAG,"speedPer="+speedPer);
        tv_schedule.setText(speedPer+"%");
        progressBar.setProgress((int)speedPer);
        setTextViewWidth(tv_schedule,view,speedPer);
    }
 
    private void setTextViewWidth(TextView textView,View view,float speed) {
        Paint paint = new Paint();
        float textWidth = paint.measureText(textView.getText().toString());
        Log.d(TAG,"textWidth="+textWidth);
        LinearLayout.LayoutParams params = (LinearLayout.LayoutParams) textView.getLayoutParams();
        LinearLayout.LayoutParams params1 = (LinearLayout.LayoutParams) view.getLayoutParams();
        if (textWidth > speed) {
            params.weight = textWidth;
            params1.weight = 100 - textWidth;
        } else {
            params.weight = speed;
            params1.weight = 100 - speed;
        }
 
    }
}

activity_custom_view.xml

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".custom.CustomViewActivity">
    <LinearLayout
        android:layout_marginTop="20px"
        android:layout_marginHorizontal="30px"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
        <TextView
            android:text="進(jìn)度:"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"/>
        <RelativeLayout
            android:layout_weight="4"
            android:layout_width="0dp"
            android:layout_height="wrap_content">
            <ProgressBar
                android:id="@+id/progressbar"
                style="@android:style/Widget.ProgressBar.Horizontal"
                android:max="100"
                android:progress="50"
                android:progressDrawable="@drawable/progress_drawable"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"/>
            <LinearLayout
                android:orientation="horizontal"
                android:layout_width="match_parent"
                android:layout_height="wrap_content">
                <TextView
                    android:id="@+id/tv_schedule"
                    android:text=""
                    android:gravity="center_horizontal"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="wrap_content"/>
                <View
                    android:id="@+id/view"
                    android:layout_weight="1"
                    android:layout_width="0dp"
                    android:layout_height="20px"/>
            </LinearLayout>
        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

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

相關(guān)文章

  • Android本地搜索業(yè)務(wù)優(yōu)化方案

    Android本地搜索業(yè)務(wù)優(yōu)化方案

    這篇文章主要為大家介紹了Android本地搜索業(yè)務(wù)優(yōu)化方案詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪
    2023-05-05
  • 淺談Viewpager和輪播圖的沖突解決方法

    淺談Viewpager和輪播圖的沖突解決方法

    下面小編就為大家?guī)硪黄獪\談Viewpager和輪播圖的沖突解決方法。小編覺得挺不錯(cuò)的,現(xiàn)在就分享給大家,也給大家做個(gè)參考。一起跟隨小編過來看看吧
    2017-04-04
  • Android實(shí)現(xiàn)簡(jiǎn)單點(diǎn)贊動(dòng)畫

    Android實(shí)現(xiàn)簡(jiǎn)單點(diǎn)贊動(dòng)畫

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)簡(jiǎn)單點(diǎn)贊動(dòng)畫,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2021-08-08
  • Flutter開發(fā)之Shortcuts快捷鍵組件的用法詳解

    Flutter開發(fā)之Shortcuts快捷鍵組件的用法詳解

    在桌面端的開發(fā)中,鍵盤快捷鍵是非常常見而必要的,F(xiàn)lutter?既然可以開發(fā)桌面端應(yīng)用,那必然要提供自定義快捷鍵,所以本文就來和大家講講Shortcuts組件的簡(jiǎn)單使用吧
    2023-05-05
  • Android App更改應(yīng)用的圖標(biāo)的實(shí)現(xiàn)方法

    Android App更改應(yīng)用的圖標(biāo)的實(shí)現(xiàn)方法

    這篇文章主要介紹了Android App更改應(yīng)用的圖標(biāo)的實(shí)現(xiàn)方法的相關(guān)資料,主要是通過入口Activity android:icon="@drawable/new_app_icon" 指向新的應(yīng)用圖標(biāo),需要的朋友可以參考下
    2017-08-08
  • Android實(shí)現(xiàn)長按圖片保存至相冊(cè)功能

    Android實(shí)現(xiàn)長按圖片保存至相冊(cè)功能

    這篇文章主要為大家詳細(xì)介紹了Android實(shí)現(xiàn)長按圖片保存至相冊(cè)功能,具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下
    2017-03-03
  • Android BaseAdapter應(yīng)用實(shí)例

    Android BaseAdapter應(yīng)用實(shí)例

    這篇文章主要介紹了Android BaseAdapter應(yīng)用方法,結(jié)合生成聯(lián)系人Items的實(shí)例形式分析了BaseAdapter的使用技巧,需要的朋友可以參考下
    2016-01-01
  • 詳解Android性能優(yōu)化之內(nèi)存泄漏

    詳解Android性能優(yōu)化之內(nèi)存泄漏

    內(nèi)存泄漏(memory leak)是指由于疏忽或錯(cuò)誤造成程序未能釋放已經(jīng)不再使用的內(nèi)存。本篇文章主要介紹了Android性能優(yōu)化之內(nèi)存泄漏,有興趣的可以了解一下。
    2016-12-12
  • Android開發(fā)之AlarmManager的用法詳解

    Android開發(fā)之AlarmManager的用法詳解

    這篇文章主要介紹了Android開發(fā)之AlarmManager的用法,是Android應(yīng)用開發(fā)中非常實(shí)用的技能,需要的朋友可以參考下
    2014-07-07
  • Android開發(fā)之基于RecycleView實(shí)現(xiàn)的頭部懸浮控件

    Android開發(fā)之基于RecycleView實(shí)現(xiàn)的頭部懸浮控件

    RecyclerView是一種類似于ListView的一個(gè)滑動(dòng)列表,但是RecyclerView和ListView相比,RecyclerView比ListView更好,這篇文章重點(diǎn)給大家介紹基于RecycleView實(shí)現(xiàn)的頭部懸浮控件,感興趣的朋友一起看看吧
    2019-10-10

最新評(píng)論