在Android中滑动时缩小的Seekbar按钮(带有自己的拇指xml)

时间:2014-11-12 12:49:15

标签: android xml android-layout

我遇到了Android SeekBar的问题。

当我使用标准拇指(蓝色)时,没关系,但是当我使用自己的主题如scrubber_control.xml时出现问题 - 按钮缩小了。我已经尝试设置最小高度,填充,添加高度/宽度到scrubber_control项目,但无法解决这个奇怪的问题。

enter image description here

布局

<SeekBar
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="@+id/question_seekbar"
android:thumb="@drawable/scrubber_control"
/>

scrubber_control.xml

<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_enabled="false" android:drawable="@drawable/scrubber_control_disabled_holo" />
<item android:state_pressed="true" android:drawable="@drawable/scrubber_control_pressed_holo" />
<item android:state_selected="true" android:drawable="@drawable/scrubber_control_focused_holo" />
<item android:drawable="@drawable/scrubber_control_normal_holo" />
</selector>

1 个答案:

答案 0 :(得分:1)

在drawable中创建自定义形状xmls,用于定义拇指的高度和宽度

用于scrubber_control.xml

中使用的所有三种形状

例如:

在drawable文件夹中添加这些xmls

custom_scrubber_control_pressed_holo.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape>
        <size
            android:height="40dp"
            android:width="40dp" />

        <solid android:color="@android:color/transparent" />
    </shape>
</item>
<item android:drawable="@drawable/scrubber_control_pressed_holo"/>

</layer-list>

custom_scrubber_control_focused_holo.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape>
        <size
            android:height="40dp"
            android:width="40dp" />

        <solid android:color="@android:color/transparent" />
    </shape>
</item>
<item android:drawable="@drawable/scrubber_control_focused_holo"/>

</layer-list>

custom_scrubber_control_disabled_holo.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape>
        <size
            android:height="40dp"
            android:width="40dp" />

        <solid android:color="@android:color/transparent" />
    </shape>
</item>
<item android:drawable="@drawable/scrubber_control_disabled_holo"/>

</layer-list>

custom_scrubber_control_normal_holo.xml

<layer-list xmlns:android="http://schemas.android.com/apk/res/android" >

<item>
    <shape>
        <size
            android:height="40dp"
            android:width="40dp" />

        <solid android:color="@android:color/transparent" />
    </shape>
</item>
<item android:drawable="@drawable/scrubber_control_normal_holo"/>

</layer-list>

之后你只需要改变你的选择器。

<selector xmlns:android="http://schemas.android.com/apk/res/android">
 <item android:state_enabled="false"  android:drawable="@drawable/custom_scrubber_control_disabled_holo" />
 <item android:state_pressed="true" android:drawable="@drawable/custom_scrubber_control_pressed_holo" />
 <item android:state_selected="true" android:drawable="@drawable/custom_scrubber_control_focused_holo" />
 <item android:drawable="@drawable/custom_scrubber_control_normal_holo" />
 </selector>