繁体   English   中英

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

[英]How to increase clickable area for thumb of a seekbar in 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"/>

使用以下代码,可以增加任何视图可点击区域:

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);
                }
            };
        });

    }

是完整的演示代码

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM