我已经实现了一个简单的 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));
}
});
这是我的drawables
-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- 如何修复搜索栏拇指居中问题设置等于或小于上面提到的和here-
minHeight
stackoverflow-自定义搜索栏拇指垂直位置问题maxHeight
layout_height
看过这里,但我没有使用任何自定义进度drawable- stackoverflow-android marshmallow 自定义搜索栏进度条未显示
非常欢迎任何帮助或建议。