2013-02-17 106 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的透明區域)