Android 位于ScrollView或ViewPager后面的视图如何接收单击事件?
我有一个位于ScrollView后面的视图,需要该视图是可点击的。如果是RelativeLayout或FrameLayout,则没有问题。但在ScrollView或ViewPager的情况下,我的面纱永远不会被点击 不工作-未单击iv1:Android 位于ScrollView或ViewPager后面的视图如何接收单击事件?,android,layout,view,onclick,overlay,Android,Layout,View,Onclick,Overlay,我有一个位于ScrollView后面的视图,需要该视图是可点击的。如果是RelativeLayout或FrameLayout,则没有问题。但在ScrollView或ViewPager的情况下,我的面纱永远不会被点击 不工作-未单击iv1: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_he
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#888"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Layer 1"
android:textColor="#fff"
android:gravity="center" />
<ImageView
android:id="@+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_centerHorizontal="true"
android:src="@drawable/list_button" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#50ff0000"
android:paddingTop="20dp" >
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#5000ff00">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Layer 2"
android:textColor="#fff"
android:gravity="center" />
</ScrollView>
<ImageView
android:id="@+id/iv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_centerHorizontal="true"
android:src="@drawable/list_button" />
</RelativeLayout>
</RelativeLayout>
工作-iv1可勾选:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#888"
>
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Layer 1"
android:textColor="#fff"
android:gravity="center" />
<ImageView
android:id="@+id/iv1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_centerHorizontal="true"
android:src="@drawable/list_button" />
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#50ff0000"
android:paddingTop="20dp" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Layer 2"
android:textColor="#fff"
android:gravity="center" />
<ImageView
android:id="@+id/iv2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="20dp"
android:layout_centerHorizontal="true"
android:src="@drawable/list_button" />
</RelativeLayout>
</RelativeLayout>
是否可以更正此问题?您的imageView iv1不在ScrollView中。在查看页面中包含此布局是否有问题?我需要iv1位于ScrollView或ViewPager的后面,而不是位于第1层:iv1、第2层:ScrollView或ViewPager的上面。我认为点击是不可能的,因为滚动和寻呼机都会截获onToch*事件,而不会通过层次结构传递这些事件。在我的示例中,ScrollView仅用于示例。这是事实,如果需要单击,您必须克服这些限制。您也可以尝试使用gtofront方法单击它。。。但是如果你不想看到它,你可以将它的可见性设置为默认值。。。因此,用户不会看到它,但可以单击它。您的imageView iv1不在ScrollView中。在查看页面中包含此布局是否有问题?我需要iv1位于ScrollView或ViewPager的后面,而不是位于第1层:iv1、第2层:ScrollView或ViewPager的上面。我认为点击是不可能的,因为滚动和寻呼机都会截获onToch*事件,而不会通过层次结构传递这些事件。在我的示例中,ScrollView仅用于示例。这是事实,如果需要单击,您必须克服这些限制。您也可以尝试使用gtofront方法单击它。。。但是如果你不想看到它,你可以将它的可见性设置为默认值。。。所以它不会被用户看到,但可以被点击。