【问题标题】:Seekbar and InsetDrawable for progressSeekbar 和 InsetDrawable 获取进度
【发布时间】:2011-04-01 13:43:33
【问题描述】:

您好,我尝试自定义搜索栏。

这是我的问题:

main.xml

   ...
    <SeekBar android:id="@+id/seekBar1" 
                android:layout_width="match_parent" 
                android:layout_height="wrap_content" 
                android:layout_alignParentLeft="true"
                android:thumb="@drawable/seekbarthumb"
                android:progressDrawable="@drawable/sb2"
                android:minHeight="45dip"
                android:maxHeight="45dip"
            ></SeekBar>
    ...

@drawable 中的 sb2.xml

<layer-list  xmlns:android="http://schemas.android.com/apk/res/android">   
<item android:id="@android:id/background" 
    android:drawable="@drawable/seekbarbg">
</item>
<item android:id="@android:id/progress"
    android:drawable="@drawable/sb_progress">
</item>
</layer-list>

一切正常,但 sb_progress 位置错误。

所以我有 2 个解决方案。更改 sb_progress 的位置或使用 Photoshop 编辑 sb_progress 并添加透明像素来修复它。

通过尝试改变位置的好方法出了问题:

我在 sb2.xml 中添加了一些行

<layer-list  xmlns:android="http://schemas.android.com/apk/res/android">   
<item android:id="@android:id/background" 
    android:drawable="@drawable/seekbarbg">
</item>
<item android:id="@android:id/progress" >
    <inset
    android:drawable="@drawable/sb_progress" 
    android:insetTop="11dip"
    android:insetBottom="11dip"
    android:insetLeft="11dip">
    </inset>
</item>
</layer-list>  

我添加了inset 元素,但结果为 suxx。位置正确,但进度不再动画。 sb_progress.png 始终是完整绘制的,不会停留在拇指上。

我需要帮助!这是一个错误,我需要添加透明像素吗?不是

InsetDrawable 是 Drawable 的子类。为什么搜索栏不再适用于 InsetDrawable。

java.lang.Object ↳ android.graphics.drawable.Drawable ↳ android.graphics.drawable.InsetDrawable

【问题讨论】:

    标签: android xml seekbar


    【解决方案1】:

    我知道这是一个老问题,但如果有人通过搜索引擎找到了这个问题(就像我所做的那样),您需要做的就是在可绘制对象和插图中添加一个“剪辑”。

    <item android:id="@android:id/progress" >
        <clip>
        <inset
            android:insetRight="11dp"
            android:insetLeft="11dp">
            <shape>
                 <solid android:color="#343434"/>
            </shape>
        </inset>
        </clip>
    </item>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-04-05
      • 1970-01-01
      • 2012-04-05
      • 1970-01-01
      • 2017-08-16
      • 1970-01-01
      相关资源
      最近更新 更多