更改搜索栏拇指的大小 [英] Changing size of seekbar thumb

查看:35
本文介绍了更改搜索栏拇指的大小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有

android:thumb="@drawable/thumb"

如何以dip 为单位设置此拇指的大小?因为我为seekbar使用了一种样式,如

How can I set the size of this thumb in dip unit? Because I use a style for seekbar like

<style name="CustomSeekBar">
    <item name="android:indeterminateOnly">false</item>
    <item name="android:minHeight">8dip</item>
    <item name="android:maxHeight">8dip</item>
    <item name="android:thumbOffset">8dip</item>
</style> 

并且我想要具有 12dip 高度和宽度的拇指.

and I want to have the thumb with 12dip height and width.

推荐答案

对我来说设置拇指大小最灵活的方法是创建 layered-drawable 以形状作为占位符 thumb_image.xml::>

The most flexible way to set thumb size for me is to create layered-drawable with shape as placeholder thumb_image.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>

所以基本上改变形状的大小会拉伸可绘制,形状是透明的所以它不可见.同样,这种拇指的最小尺寸是位图的尺寸.

So basically changing the size of shape will stretch drawable, the shape is transparent so it won't be visible. Also the minimum size of such thumb is size of bitmap.

这是布局示例:

<SeekBar
    android:id="@+id/seekBar1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:thumb="@drawable/thumb_image" />

<SeekBar
    android:id="@+id/seekBar2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content" />

这篇关于更改搜索栏拇指的大小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆