gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-30 02:25:04 24 4
gpt4 key购买 nike

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

  <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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com