触摸或拖动拇指时,我的Seekbar不会更新其在UI上的进度

时间:2019-01-16 13:38:23

标签: android seekbar

我必须在活动中添加搜寻栏,使其与底部对齐,但无法正常工作。当我触摸条形图或拖动拇指时,我能够在OnProgressChanged()中获得回调,但是UI尚未更新。结果,Thumb保持在其原始位置。

这是我的代码:

layout.xml:

<android.support.design.widget.CoordinatorLayout
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:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">

<!-- other content-->
<SeekBar
    android:id="@+id/sb_volume"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginBottom="@dimen/_16sdp"
    android:layout_marginRight="@dimen/_16sdp"
    android:layout_marginLeft="@dimen/_16sdp"
    android:layout_gravity="bottom"
    android:max="10"
    android:progressDrawable="@drawable/sb_volume"
    android:thumb="@drawable/sb_thumb"
    />

Activity.java:

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.layout);
    sb_volume = findViewById(R.id.sb_volume);
    sb_volume.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
        @Override
        public void onProgressChanged(SeekBar seekBar, int i, boolean b) {
            Toast.makeText(HomeActivity.this, "Progress :" + seekBar.getProgress(), Toast.LENGTH_LONG).show();
        }

        @Override
        public void onStartTrackingTouch(SeekBar seekBar) {

        }

        @Override
        public void onStopTrackingTouch(SeekBar seekBar) {

        }
    });
}

预先感谢!

0 个答案:

没有答案