gpt4 book ai didi

android - 无法在启用 FastScroll 的 ListView 上选择右键

转载 作者:塔克拉玛干 更新时间:2023-11-03 00:59:16 25 4
gpt4 key购买 nike

我有一个 ListView,左侧有图像,中间有标题和副标题,右侧有一个 ImageButton(此按钮右侧没有任何边距)。

enter image description here

<ListView
android:id="@+id/contacts"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:cacheColorHint="@android:color/transparent"
android:fastScrollEnabled="true"
android:scrollbarStyle="outsideInset"/>

我为此 ListView 启用了快速滚动。当我尝试单击右侧的 ImageButton 时,滚动条成为焦点并且 ListView 开始滚动。我无法选择右侧的按钮。请帮帮我。

最佳答案

您需要覆盖 ListView 类及其 onInterceptTouchEvent 方法。

public class CustomListView extends ListView {
public CustomListView(Context context, AttributeSet attrs) {
super(context, attrs);
}

@Override
public boolean onInterceptTouchEvent(MotionEvent ev) {
setFastScrollEnabled(false);
boolean possibleResult = super.onInterceptTouchEvent(ev);
setFastScrollEnabled(true);

boolean actualResult = super.onInterceptTouchEvent(ev);

if (ev.getAction() == MotionEvent.ACTION_DOWN) {
return possibleResult && actualResult;
}

return super.onInterceptTouchEvent(ev);
}
}

它看起来像:
enter image description here

但是,您观察到的问题是预期的行为。
正确的解决方法是在行尾添加填充。

看看 Google 的 PhoneBook 应用程序,例如:
enter image description here
正如您在此处看到的,单元格大小小于屏幕宽度的 100%。

希望对你有帮助

关于android - 无法在启用 FastScroll 的 ListView 上选择右键,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35008505/

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