搜索栏和InsetDrawable进步 [英] Seekbar and InsetDrawable for progress

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

问题描述

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

Hi I try to customize a seekbar.

下面是我的问题:

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>
    ...

sb2.xml在@drawable

sb2.xml in @drawable

<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是在错误的位置。

Everything works fine, but the sb_progress was on the wrong position.

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

So i have 2 solutions. Change the position of the sb_progress or edit sb_progress with Photoshop and add transparent pixels to fix it.

通过尝试改变立场东西的好方法出了问题:

By trying the good way of changing the position something went wrong:

我添加了一些线到sb2.xml

i added some lines to the 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>  

我添加了插图的元素,但结果suxx 。该位置是正确的,但进度不再动画。该sb_progress.png总是充满绘制,不要停在大拇指。

I added the inset element, but the result suxx. the position is correct but the progress isn't animating anymore. The sb_progress.png is always full drawn and don't stop at the thumb.

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

I need help! Is this a Bug and I need to add transparent Pixels? Isn't

InsetDrawable绘制对象的子类。为什么搜索栏不会再有InsetDrawable无法正常工作。

InsetDrawable a subclass of Drawable. Why the seekbar doesn't work anymore with an InsetDrawable.

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

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

推荐答案

我知道这是一个老问题,但如果有人认为这通过搜索引擎(像我一样),所有你需要做的就是添加一个夹子以绘制以及一个插图。

I know this is an old question, but if anyone finds this through a search engine (like I did) all you need to do is add a 'clip' to the drawable as well as an inset.

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

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

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