欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  移动技术

安卓常用View视图开发技巧

程序员文章站 2022-07-05 19:43:03
本篇常用的View如图中所示:xml布局代码

本篇常用的View如图中所示:

安卓常用View视图开发技巧

xml布局代码

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="horizontal">

        <ProgressBar
            android:id="@+id/pb_progress_load"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="请稍候" />
    </LinearLayout>

    <ProgressBar
        android:id="@+id/pb_progress_loading"
        style="?android:progressBarStyleHorizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />

    <SeekBar
        android:id="@+id/sb_progress_loading"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" />
    <TextView
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:text="1.随便写凑字数的\n2.GODVGODVGODV"/>
</LinearLayout>

java代码

public class ProgressActivity extends AppCompatActivity {
    private ProgressBar pb_progress_load;
    private ProgressBar pb_progress_loading;
    private SeekBar sb_progress_loading;

    private SeekBar.OnSeekBarChangeListener onSeekBarChangeListener = new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {

        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {
            pb_progress_loading.setProgress(seekBar.getProgress());
            if (seekBar.getProgress() == seekBar.getMax()) {
                pb_progress_load.setVisibility(View.GONE);
            } else {
                pb_progress_load.setVisibility(View.VISIBLE);
            }
        }
    };


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_progress);
        pb_progress_load = findViewById(R.id.pb_progress_load);
        pb_progress_loading = findViewById(R.id.pb_progress_loading);
        sb_progress_loading = findViewById(R.id.sb_progress_loading);

        sb_progress_loading.setOnSeekBarChangeListener(onSeekBarChangeListener);


    }
} 

本文地址:https://blog.csdn.net/we1less/article/details/107733826