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

android自定義進度條移動效果

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

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

自定義進度條,效果如下:

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="進度:"
            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)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持腳本之家。

相關(guān)文章

最新評論

花垣县| 怀安县| 苍山县| 若羌县| 望谟县| 东海县| 龙口市| 大新县| 琼海市| 阜南县| 秦安县| 河南省| 上饶县| 敖汉旗| 商水县| 南漳县| 阿瓦提县| 河东区| 泸州市| 镇雄县| 阳原县| 丘北县| 西盟| 大兴区| 涞水县| 平原县| 新乐市| 莱芜市| 衡东县| 沂源县| 西吉县| 浦县| 新竹市| 龙山县| 堆龙德庆县| 琼海市| 通海县| 钟祥市| 桦南县| 柘城县| 和田县|