嘿,我的Android应用程序中有网格布局。我想在我的RelativeLayout上使用OnClickListener。但这不起作用。
这是我的布局:
<RelativeLayout
android:id="@+id/menu_button_logout"
android:background="@color/tran_colorYellow"
android:layout_height="fill_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:clickable="true">
<ImageView
android:id="@+id/categoria_image_2"
android:src="@drawable/logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"/>
<TextView
android:text="Abmelden"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_below="@+id/categoria_image_2"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="@color/white"/>
</RelativeLayout>
这是我的代码:
relativeLayoutLogout = (RelativeLayout)findViewById(R.id.menu_button_logout);
relativeLayoutLogout.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
mAuth.getInstance().signOut();
}
});
最佳答案
尝试将此行添加到子视图android:clickable="false"
:
<RelativeLayout
android:id="@+id/menu_button_logout"
android:background="@color/tran_colorYellow"
android:layout_height="fill_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:gravity="center"
android:clickable="true">
<ImageView
android:id="@+id/categoria_image_2"
android:src="@drawable/logo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:clickable="false"/>
<TextView
android:text="Abmelden"
android:layout_height="wrap_content"
android:layout_width="fill_parent"
android:gravity="center"
android:layout_below="@+id/categoria_image_2"
android:textAllCaps="true"
android:textStyle="bold"
android:textColor="@color/white"
android:clickable="false"/>
</RelativeLayout>
关于java - 如何将OnClickListener用于RelativeLayout ViewGroup?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/42601165/