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

标签 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"/>

最佳答案

使用下面的代码可以增加任何 View 可点击区域:

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是完整的演示代码

关于android - 如何增加android中搜索栏拇指的可点击区域?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27984326/

相关文章:

android - 如何从MySQL访问android应用程序中的数据并在离线模式下显示?

java - Android:从 EmojiconEditText 获取表情符号

机器人 : Know build info of my application

android - 使用 Robolectric 测试菜单

android - 我正在 Linux 中编写 eMMC 驱动程序并从 JNI 应用程序访问 IOCTL。失败,错误代码 13(权限被拒绝)

java - 更改 java/android 中调试和生产的值

java - 使用 ksoap2 捕获 .net webservice out 参数

java - Flutter构建发布APK报NoSuchMethodException错误

android - 我们如何根据设备在 Android 中设置 Activity 的方向?

java - Android 应用程序不会写入 Firebase 实时数据库