2013-02-17 40 views
1

我有一个自定义搜索栏自定义搜索栏layerlist不工作​​。首先九个补丁图像:安卓预期

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:id="@android:id/background"> 
     <shape> 
      <corners android:bottomLeftRadius="4px" android:topLeftRadius="4px" android:topRightRadius="4px" android:bottomRightRadius="4px"/> 
      <gradient android:startColor="@color/dark_grey" android:endColor="@color/light_grey" android:angle="-90.0" /> 
     </shape> 
    </item> 
    <item android:id="@android:id/secondaryProgress"> 
     <clip> 
      <shape> 
       <corners android:bottomLeftRadius="4px" android:topLeftRadius="4px" android:topRightRadius="4px" android:bottomRightRadius="4px"/> 
      <gradient android:startColor="@color/dark_grey" android:endColor="@color/light_grey" android:angle="-90.0" /> 
      </shape> 
     </clip> 
    </item> 
    <item android:id="@android:id/progress"> 
     <clip> 
      <shape> 
       <corners android:bottomLeftRadius="4px" android:topLeftRadius="4px" android:topRightRadius="4px" android:bottomRightRadius="4px"/> 
       <gradient android:startColor="@color/orange" android:endColor="@color/orange" android:centerColor="@color/light_orange" android:angle="90.0" /> 
      </shape> 
     </clip> 
    </item> 
</layer-list> 

这是应该的样子:enter image description here

这是怎么看起来像图像

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
    <item android:id="@android:id/background"   android:drawable="@drawable/slider_bar_track"></item> 
    <item android:id="@android:id/secondaryProgress" android:drawable="@drawable/slider_bar_track"></item> 
    <item android:id="@android:id/progress"    android:drawable="@drawable/slider_bar_hlt" ></item> 
</layer-list> 
的项目和梯度

其次: enter image description here 高度过高(进度,背景和拇指png都是12像素高,其中背景和进度png在顶部和底部具有透明像素,以使它们具有相同的高度)enter image description hereenter image description hereenter image description here我有这三个文件在res文件夹中的所有密度与相同的大小(我想他们是)。 此外,进展始终延伸到SeekBar的整个宽度。我试图改变图层列表的顺序,但无济于事。

当层使用列表中的形状,它看起来像这样:enter image description here 这里,至少,进度是正确的,但高度依然太高。

在这种情况下,我需要那些高度相同(12px,而不是dp)的所有密度。屏幕截图来自xhdpi设备。可绘制进度的高度与mdpi设备上的大拇指相同。我怎样才能让它们在所有设备上看起来都一样,并且可绘制的进度比拇指更小?

+0

ok,则该高度问题可以使用ben75s答案被固定和我设法解决进度问题使用插入drawable而不是一个普通的drawable(不知道什么工作,但它做到了)[链接](http://stackoverflow.com/questions/5514236/seekbar-and- insetdrawable换进度) – user1628803 2013-02-17 23:14:35

回答

2

问题是你的进度和背景PNG的左边界上定义的可扩展区域。

可延展区域目前正好像左边缘中间的1像素宽。这意味着你的PNG的水平中心线将被拉伸。但你需要的是“拉伸透明区域”。

要这么做:

  • 取出黑色像素的左边缘的中间。
  • 在添加上的左边缘2个黑色像素x关于y = 3且y = 9(确保它们都在PNG的透明区域)