我试图实现一个可点击的滚动视图:如何实现可点击的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>
好像滚动视图消耗所有触摸事件,因此该方法的onClick永远不会触发。有没有什么办法来保持滚动功能,并使其可点击?
这里的线性布局的目的是什么?它看起来没用。我当然有滚动视图包含linearlayits包含可点击的按钮工作正常。我想要响应用户单击滚动视图,然后将线性布局和onclick监听器分配到滚动视图。点击事件可能会被回收利用所消耗,但有一个方法 –