我正在尝试实现可点击的 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 方法。有什么方法可以保持滚动功能并使其可点击吗?
最佳答案
您能否更详细地指定您要在何处处理点击事件。 根据您的代码,您正在处理线性布局上的点击事件。 下面的帖子可能会对您有所帮助。
关于android - 如何实现可点击的ScrollView?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22203978/