如何增加android中搜索栏的拇指可点击区域?

时间:2015-01-16 12:47:35

标签: android

我在我的应用程序中使用了搜索栏。如何增加搜索栏拇指的触摸区域,而不增加其宽度和高度?用户发现很难使用默认的拇指大小,因此必须增加触摸区域以获得良好的用户体验。

  <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 个答案:

答案 0 :(得分: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是完整的演示代码