我已经实现了一个简单的SeekBar,当用户触摸它时,它的拇指变大。虽然这在Marshmallow设备中工作正常,但它不适用于Lollipop。
这两个问题是 -
这是我的活动布局 -
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clipChildren="false">
<SeekBar
android:id="@+id/seekBar_main_green"
android:layout_width="match_parent"
android:layout_height="30dp"
android:layout_marginTop="20dp"
android:max="255"
android:thumb="@drawable/custom_thumb_green" />
</RelativeLayout>
</ScrollView>
这是我的班级 -
sbGreen.setOnSeekBarChangeListener(new SeekBar.OnSeekBarChangeListener() {
@Override
public void onProgressChanged(SeekBar seekBar, int progress, boolean fromUser) {
// Changing background color of some other view
}
@Override
public void onStartTrackingTouch(SeekBar seekBar) {
sbGreen.setThumb(ContextCompat.getDrawable(MainActivity.this, R.drawable.custom_thumb_green_large));
}
@Override
public void onStopTrackingTouch(SeekBar seekBar) {
sbGreen.setThumb(ContextCompat.getDrawable(MainActivity.this, R.drawable.custom_thumb_green));
}
});
这是我的抽奖 -
custom_thumb -
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="10dp"
android:left="10dp"
android:right="10dp"
android:top="10dp" >
<shape android:shape="oval">
<size
android:width="10dp"
android:height="10dp" />
<solid android:color="#00af00" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#50008000"/>
<size android:height="20dp" android:width="20dp"/>
</shape>
</item>
</layer-list>
custom_thumb_large -
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item
android:bottom="30dp"
android:left="30dp"
android:right="30dp"
android:top="30dp" >
<shape android:shape="oval">
<size
android:width="10dp"
android:height="10dp" />
<solid android:color="#00af00" />
</shape>
</item>
<item>
<shape android:shape="oval">
<solid android:color="#50008000"/>
<size android:height="40dp" android:width="40dp"/>
</shape>
</item>
</layer-list>
我尝试过的事情
将maxHeight
设置为较大值,如此处所述 -
stackoverflow- how to fix seekbar bar thumb centering issues
如上所述设置minHeight
和maxHeight
等于或小于layout_height
,此处为stackoverflow- custom seekbar thumb vertical position issue
看这里,但我没有使用任何自定义进度drawable- stackoverflow- android marshmallow custom seekbar progress bar not showing
欢迎任何帮助或建议。