自定义滑块在进度条中心位置定位出现问题

3

我尝试改变SeekBar的宽度,使其更加细长。但是我的拇指没有出现在SeekBar的中心位置。拇指是一个自定义的9 patch图像。

    <?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
 >
 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/relLayout"
        android:orientation="horizontal"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
>
    <SeekBar 
        android:paddingLeft="60dp" 
        android:progressDrawable="@drawable/seekbar_progress" 
        android:progress="0" 
        android:layout_height="20dp" 
        android:layout_width="fill_parent" 
        android:id="@+id/frequency_slider" 
        android:max="1" 
        android:paddingRight="60dp" 
        android:minWidth="60dp"
        android:minHeight="60dp"
        android:layout_alignParentRight="true"

        android:thumb="@drawable/seek_normal_thumb" >
        </SeekBar>



</RelativeLayout>
<WebView  xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/webkit"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/relLayout"
    android:layout_alignParentTop="true"
/>
</RelativeLayout>

请发布完整的XML布局。 - Rejinderi
<SeekBar android:paddingLeft="60dp" android:progressDrawable="@drawable/seekbar_progress" android:progress="0" android:secondaryProgress="0" android:layout_height="25dp" android:layout_width="fill_parent" android:id="@+id/frequency_slider" android:max="1" android:paddingRight="60dp" android:thumb="@drawable/seek_normal_thumb" > </SeekBar> - Astha Devra
2个回答

6
我通过定义SeekBar的最小高度和最大高度来正确实现了它。

我只需要设置maxHeight。 :) 至于要将其设置为什么:我只是尝试了不同的dp值,直到看起来合适。 - Chani
对我来说,android:maxHeight="60dp"。真棒!谢谢。 - ahmed_khan_89

5
在定义了一个具有大maxHeight值的属性之后:
android:maxHeight="1000dp"

SeekBar 将会被调整到中心位置。


我猜这与Drawable类方法getMinimumHeight()的工作方式有关。以下是Javadoc中对其返回值的解释:“此Drawable建议的最小高度。如果此Drawable没有建议的最小高度,则返回0。” - Andrew

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接