2015-09-25 67 views
1

請查看我想要實現的自定義seekbar的以下屏幕截圖。 enter image description here如何刪除已設置自定義進度的seekbar [android]的默認指標圖標可繪製

我非常接近建立如上所示的seekbar(沒有在seekbar下面的圖像)。以下是我所做的截圖。

enter image description here

問題:

正如你可以在第二個截圖中看到,有在搜索條進度指示條後的圖標。我一直試圖擺脫這一點,但顯然不成功做到這一點。任何關於如何移除該圖標的建議/想法都會有很大的幫助。謝謝。使用

搜索欄佈局XML

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.application.todo.activityTransition.activities.SeekBarActivity"> 

<TextView 
    android:id="@+id/painLevelText" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:padding="10dp" 
    android:text="@string/painLevelText" /> 

<LinearLayout 
    android:id="@+id/radIoGroupLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/painLevelText" 
    android:orientation="vertical"> 

    <RadioGroup 
     android:id="@+id/seekBarRadioGroup" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:weightSum="10"> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:id="@+id/defaultSelection" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 

     <RadioButton 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" /> 
    </RadioGroup> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="10dp" 
     android:orientation="horizontal" 
     android:weightSum="10"> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="1" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="2" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="3" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="4" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="5" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="6" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="7" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="8" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="9" /> 

     <TextView 
      android:layout_width="0dp" 
      android:layout_height="wrap_content" 
      android:layout_weight="1" 
      android:gravity="center" 
      android:text="10" /> 

    </LinearLayout> 

</LinearLayout> 

<RelativeLayout 
    android:id="@+id/seekBarLayout" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/radIoGroupLayout" 
    android:background="@drawable/seekbar_layout_background"> 

    <SeekBar 
     android:id="@+id/seekBar" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:max="10" 
     android:progress="5" 
     android:progressDrawable="@drawable/custom_seek_bar" /> 

    <TextView 
     android:id="@+id/seekBarProgressValue" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerInParent="true" 
     android:gravity="center" 
     android:padding="10dp" 
     android:textColor="#FFF" 
     android:textSize="15sp" /> 
</RelativeLayout> 


</RelativeLayout> 

自定義繪製對象文件搜索條

<?xml version="1.0" encoding="utf-8"?> 
<layer-list xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:id="@android:id/progress"> 
    <clip> 
     <shape android:shape="rectangle"> 
      <size 
       android:width="12dp" 
       android:height="12dp" /> 
      <corners android:radius="15dp" /> 

      <solid android:color="#FF8D1E" /> 

      <gradient 
       android:angle="270" 
       android:centerColor="#FF8D1E" 
       android:endColor="#FF971F" 
       android:startColor="#FF971F" /> 
     </shape> 
    </clip> 
</item> 
</layer-list> 

請找我下答案部分答案

+1

檢查URL http://stackoverflow.com/questions/20855815/how-to-hide- show-thumb-draw-in-a-seekbar – Pavya

+0

請張貼您的活動代碼 –

回答

5

link有助於實現預期的結果。但是我發現一個問題,而使用下面的一行代碼

seekBar.getThumb().mutate().setAlpha(0); 

它取出拇指在最後,但是當我們從RadioGroup中選擇「10」進度指示器被砍傷。以下是相關圖片。

enter image description here

但是,當我在我的佈局中使用的XML標籤中的搜索條,有人按預期工作。

android:thumb="@null" 

圖片

enter image description here

不知道這是正確的做法,但它的伎倆。

0

我不認爲做SeekBar是正確的實現你的用例。嘗試使用ProgressBar代替,那麼你不必擔心拇指。

+0

Hey Kent,感謝您在發佈回覆時的時間。你能建議任何鏈接/參考,我可以找到關於進度條實施入門的信息嗎? –

+0

只需在您的XML佈局和您的活動/片段中將ProgressBar替換爲SeekBar,您應該沒問題。 –

+0

會很快做到這一點,併發布更新 –

1

試試這個

android:splitTrack="false" 
seekbar.getThumb().mutate().setAlpha(0); 
1

只是把這個線在你的搜索欄的XML代碼..

  android:thumbTint="@android:color/transparent" 
相關問題