gpt4 book ai didi

android - 相对布局不可点击

转载 作者:行者123 更新时间:2023-11-29 19:15:39 24 4
gpt4 key购买 nike

下面是我的 xml:

     <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/white"
android:orientation="horizontal"
android:weightSum="2">
<RelativeLayout
android:clickable="true"
android:id="@+id/rel1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">

<com.app.thelist.view.CustomButton
android:clickable="false"
android:focusable="false"
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:text="btn1"
android:textAllCaps="false"
android:textColor="@color/txt_sub_title"
android:textSize="@dimen/txt_barselection_size"
app:FontEnum="regular" />

<com.app.thelist.view.CustomTextView
android:clickable="false"
android:focusable="false"
android:id="@+id/txt1"
style="@style/RegularFont"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/btn_my_drinks"
android:background="@drawable/border_gry_theme"
android:padding="@dimen/dimen_3"
android:text="00"
android:textColor="@color/txt_sub_title"
android:textSize="@dimen/txt_single_view_font" />

<ImageView
android:id="@+id/iv_bootm_selecter2"
android:layout_width="match_parent"
android:layout_height="7dp"
android:layout_below="@id/btn1"
android:scaleType="fitXY" />

</RelativeLayout>
<RelativeLayout
android:clickable="true"
android:id="@+id/rel1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center">

<com.app.thelist.view.CustomButton
android:clickable="false"
android:focusable="false"
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:text="btn1"
android:textAllCaps="false"
android:textColor="@color/txt_sub_title"
android:textSize="@dimen/txt_barselection_size"
app:FontEnum="regular" />

<com.app.thelist.view.CustomTextView
android:clickable="false"
android:focusable="false"
android:id="@+id/txt1"
style="@style/RegularFont"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/btn_my_drinks"
android:background="@drawable/border_gry_theme"
android:padding="@dimen/dimen_3"
android:text="00"
android:textColor="@color/txt_sub_title"
android:textSize="@dimen/txt_single_view_font" />

<ImageView
android:id="@+id/iv_bootm_selecter2"
android:layout_width="match_parent"
android:layout_height="7dp"
android:layout_below="@id/btn1"
android:scaleType="fitXY" />

</RelativeLayout>
</LinearLayout>

我已经完成了 findViewby id 并将点击监听器添加到相对布局..但它没有采取点击事件..而是在我点击相对布局内的 textview 时生成点击事件。

可能是什么问题?

谢谢。

最佳答案

点击事件从子级传递到父级。如果任何子项可点击,则第一个子项获得点击事件,如果子项不可点击,则点击事件传递给父项。

如果父 View 希望在 subview 之前发生点击事件,则需要在父 View 类中覆盖 onInterceptTouchEvent(MotionEvent ev);

但如果不想这样做,那么一个简单的解决方案就是让 child 不可点击。请在您的案例中找到编辑后的 ​​XML 代码。

<RelativeLayout
android:clickable="true"
android:id="@+id/rel1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center"
android:focusable="true"
android:focusableInTouchMode="true">

<com.app.thelist.view.CustomButton
android:id="@+id/btn1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:layout_gravity="center"
android:background="@android:color/transparent"
android:text="btn1"
android:clickable="false"
android:focusable="false"
android:textAllCaps="false"
android:textColor="@color/txt_sub_title"
android:textSize="@dimen/txt_barselection_size"
app:FontEnum="regular" />

<com.app.thelist.view.CustomTextView
android:id="@+id/txt1"
style="@style/RegularFont"
android:layout_centerVertical="true"
android:layout_toRightOf="@id/btn_my_drinks"
android:background="@drawable/border_gry_theme"
android:padding="@dimen/dimen_3"
android:text="00"
android:clickable="false"
android:focusable="false"
android:textColor="@color/txt_sub_title"
android:textSize="@dimen/txt_single_view_font" />

<ImageView
android:id="@+id/iv_bootm_selecter2"
android:layout_width="match_parent"
android:layout_height="7dp"
android:clickable="false"
android:focusable="false"
android:layout_below="@id/btn1"
android:scaleType="fitXY" />

</RelativeLayout>

关于android - 相对布局不可点击,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43602352/

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