自定義seekbar中,thumb被覆蓋掉一部分問題

 (圖一)             (圖二)        (圖三)

 

做一個自定義的seekbar,更改其背景圖片:

[java] view plain copy
  1. <com.<a href="http://lib.csdn.net/base/android" class='replace_word' title="Android知識庫" target='_blank' style='color:#df3434; font-weight:bold;'>Android</a>.Progress  
  2.                 <a href="http://lib.csdn.net/base/android" class='replace_word' title="Android知識庫" target='_blank' style='color:#df3434; font-weight:bold;'>android</a>:id="@+id/focus_seekbar"  
  3.                 android:layout_width="wrap_content"  
  4.                 android:layout_height="wrap_content"  
  5.                 android:layout_below="@id/seekbar_add"     
  6.                 android:progressDrawable="@drawable/seekbar_img"   
  7.                 android:thumb="@drawable/thumb"      
  8.                 android:max = "60"/>  
 

定義progressDrawable即爲背景圖片。thumb爲滑塊圖片

如上定義xml文件,啓動程序,生成如圖一。 thumb滑塊不能顯示完全,一部分被隱藏掉。

 

增加屬性:

[java] view plain copy
  1. android:thumbOffset="0dip"  
   

即可實現thumb不被覆蓋,即最下方位置如圖三所示,不會出現圖一情況。

網上有個豎直的VerticalSeekBar,簡單說一下他的使用:

當滑塊的大小比下面的背景大時,此時要設置

                android:minHeight="19dip" 
                android:maxHeight="19dip"

19dip即爲seek_img圖片的寬度。

而控件的layout_width值即位滑塊的width和height值

[xhtml] view plain copy
  1. <com.android.VerticalSeek  
  2.                 android:id="@+id/focus_seekbar"  
  3.                 android:layout_width="wrap_content"  
  4.                 android:layout_height="wrap_content"                  
  5.                 android:progressDrawable="@drawable/seekbar_img"    
  6.                 android:thumb="@drawable/thumb"   
  7.                 android:thumbOffset="0dip"  
  8.                 android:max = "59"  
  9.                 android:layout_centerVertical="true"                 
  10.                 android:minHeight="19dip"   
  11.                 android:maxHeight="19dip"  
  12.                 android:paddingLeft="-15dip"  
  13.                 android:paddingRight="-15dip"/>  

 

 

這麼個小問題,用了我半天時間才搞出來。網上資源太少了,給大家分享一下。

 

<?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:radius="5dip" />
            <gradient
                    android:startColor="#ff364956"
                    android:centerColor="#ff444444"
                    android:centerY="0.75"
                    android:endColor="#ff00112e"
                    android:angle="90"
            />
        </shape>
    </item>
    
    <item android:id="@android:id/secondaryProgress">
       <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#80364956"
                        android:centerColor="#802f67a6"
                        android:centerY="0.75"
                        android:endColor="#8000112e"
                        android:angle="270"
                />
            </shape>
        </clip>
    </item>
    
    <item android:id="@android:id/progress">
        <clip>
            <shape>
                <corners android:radius="5dip" />
                <gradient
                        android:startColor="#ff9ee5ff"
                        android:centerColor="#ff9ee5ff"
                        android:centerY="0.75"
                        android:endColor="#ff9ee5ff"
                        android:angle="90"
                />
            </shape>
        </clip>
    </item>
    
</layer-list>

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章