2015-01-16 102 views
1

我在我的應用程序中使用了一個seekbar。如何增加seekbar thumb的觸摸面積,而不增加它的寬度和高度?用戶覺得很難使用默認的拇指大小,所以必須增加觸摸面積以獲得良好的用戶體驗。如何在android中增加seekbar的大拇指的可點擊區域?

<SeekBar 
       android:id="@+id/seek_bar_song_progress" 
       android:layout_width="0dp" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="@dimen/padding_left_margin" 
       android:layout_weight="2.8" 
       android:gravity="center_vertical" 
       android:maxHeight="@dimen/slider_width" 
       android:progress="0" 
       style="?attr/seekbar_style" 
       android:thumbOffset="0dp" 
       android:max="@integer/song_progress_bar_upper_range" 
       android:contentDescription="@string/img_volumeslider"/> 
+1

請這個〜http://stackoverflow.com/questions/16558203/android -seekbar-touch-sensitivity –

回答

1

下面代碼的任何視圖點擊區域可以增加:

public static void increaseClickArea(View parent, View child) { 

     // increase the click area with delegateArea, can be used in + create 
     // icon 
     final View chicld = child; 
     parent.post(new Runnable() { 
      public void run() { 
       // Post in the parent's message queue to make sure the 
       // parent 
       // lays out its children before we call getHitRect() 
       Rect delegateArea = new Rect(); 
       View delegate = chicld; 
       delegate.getHitRect(delegateArea); 
       delegateArea.top -= 600; 
       delegateArea.bottom += 600; 
       delegateArea.left -= 600; 
       delegateArea.right += 600; 
       TouchDelegate expandedArea = new TouchDelegate(delegateArea, 
         delegate); 
       // give the delegate to an ancestor of the view we're 
       // delegating the 
       // area to 
       if (View.class.isInstance(delegate.getParent())) { 
        ((View) delegate.getParent()) 
          .setTouchDelegate(expandedArea); 
       } 
      }; 
     }); 

    } 

Here是完整的演示代碼

+0

這個我試過了,它只適用於一個seekbar。我在同一個佈局中有兩個搜索條,我無法爲第二個搜索條申請觸摸代理。你能幫我嗎? – Andy

+0

它適用於佈局中的多個視圖。請確保您沒有相同的保證 – KOTIOS

+0

酷將在幾個小時內恢復。 – KOTIOS