gpt4 book ai didi

android - 如何实现可点击的ScrollView?

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

我正在尝试实现可点击的 ScrollView :

findViewById(R.id.parent_view).setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
Log.d("", "onClick");
}
});




<LinearLayout
android:id="@+id/parent_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:clickable="true">

<ScrollView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="left|center_vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />

</ScrollView>

<ScrollView
android:layout_width="match_parent"
android:layout_height="50dp"
android:layout_gravity="left|center_vertical">

<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="" />

</ScrollView>
</LinearLayout>

似乎 ScrollView 消耗了所有触摸事件,因此永远不会触发 onClick 方法。有什么方法可以保持滚动功能并使其可点击吗?

最佳答案

您能否更详细地指定您想要处理点击事件的确切位置。根据您的代码,您正在处理线性布局上的点击事件。以下帖子可能对您有所帮助。

How can I set attribute onClick to a ScrollView?

关于android - 如何实现可点击的ScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22203978/

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