[英]Parent LinearLayout onclick, not called from child recyclerview
I have a linear layout, with many children views, including a recyclerview. 我有一个线性布局,有很多子视图,包括recyclerview。 I want the entire parent view to be clickable, and when the chidren are clicked I want the same thing to happen.
我希望整个父视图都是可单击的,当单击孩子时,我希望发生同样的事情。 ie I want that where ever you click in the parent view, the method will be called.
即我希望无论您在父视图中单击什么位置,都将调用该方法。
Now this is working fine, and whenever you click in the parent the method is called. 现在,这可以正常工作,每当您单击父级时,都会调用该方法。 Except the recycler view, that when I click there, nothing happens.
除了回收者视图,当我单击那里时,什么也没有发生。 I tried setting clickable and focusable of the recyclerview view to true and false, and it still didn't work.
我尝试将recyclerview视图的clickable和focusable设置为true和false,但仍然无法正常工作。
Here is my xml: 这是我的xml:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:onClick="onTodayMainPageClick"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:background="@drawable/date_background"
android:orientation="vertical"
android:padding="10dp">
<TextView
android:id="@+id/date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/colorPrimary"
android:layout_gravity="center"
android:text="1st October 2017"
android:layout_marginBottom="10dp"/>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorPrimary"/>
<TextView
android:id="@+id/whats_left_for_today_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Whats left for today"
android:textColor="@color/colorPrimary" />
<android.support.v7.widget.RecyclerView
android:id="@+id/today_recycler_view_summary"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
Thanks 谢谢
You should try doing it in following way, 您应该尝试按以下方式进行操作,
<android.support.constraint.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/linear_main"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:orientation="vertical"
android:padding="10dp"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent">
<TextView
android:id="@+id/date_text_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="10dp"
android:text="1st October 2017"
android:textColor="@color/colorPrimary" />
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@color/colorPrimary" />
<TextView
android:id="@+id/whats_left_for_today_textview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:text="Whats left for today"
android:textColor="@color/colorPrimary" />
<android.support.v7.widget.RecyclerView
android:id="@+id/today_recycler_view_summary"
android:layout_width="match_parent"
android:layout_height="200dp"
android:background="#eee"
android:paddingBottom="10dp"
android:paddingLeft="20dp"
android:paddingRight="20dp">
</android.support.v7.widget.RecyclerView>
</LinearLayout>
<View
android:id="@+id/clickable_view"
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintBottom_toBottomOf="@+id/linear_main"
android:clickable="true"
android:onClick="onTodayMainPageClick"
app:layout_constraintLeft_toLeftOf="@+id/linear_main"
app:layout_constraintRight_toRightOf="@+id/linear_main"
app:layout_constraintTop_toTopOf="@+id/linear_main" />
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.