[英]Why adnroidx recycler-view click not working when click it's item?
[英]Scrolling is not working inside recycler-view list item
我在activity_main.xml
使用了recycler-view
在card_item_list.xml中使用了多個card_item_list.xml
。 我無法滾動卡片視圖。 如果我觸摸了cardview
以外的任何地方,則效果很好。 但是,如果我點擊cardview,則recycler-view的滾動行為不起作用。
activity_main.xml中
<ViewFlipper
android:id="@+id/day_navigation"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ViewFlipper
android:id="@+id/view_flipper"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:visibility="visible">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey_ee"
android:focusableInTouchMode="true"
android:paddingBottom="35dp">
<TextView
android:id="@+id/error_container_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginLeft="15dp"
android:layout_marginRight="15dp"
android:layout_marginTop="20dp"
android:elevation="1dp"
android:gravity="center"
android:padding="10dp"
/>
<android.support.v7.widget.RecyclerView
android:id="@+id/time_duration_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/error_container_text"
android:layout_marginTop="20dp" />
<android.support.v7.widget.RecyclerView
android:id="@+id/hours_detail_recycler_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@+id/time_duration_recycler_view"
android:layout_centerHorizontal="true"
android:layout_marginTop="25dp"
android:nestedScrollingEnabled="false" />
</RelativeLayout>
card_item.xml
<RelativeLayout
android:id="@+id/errors_and_notifications_container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/divider_for_details"
android:background="@color/white"
android:paddingTop="15dp">
<android.support.v7.widget.CardView
android:id="@+id/card_view_errors"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<RelativeLayout
android:id="@+id/single_error_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/details"
android:layout_marginBottom="15dp"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp">
<ImageView
android:id="@+id/time_entry_error_image"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="@drawable/error" />
<TextView
android:id="@+id/single_error_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="45dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
<android.support.v7.widget.CardView
android:id="@+id/card_view_notifications"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/card_view_errors"
app:cardBackgroundColor="@color/white"
app:cardCornerRadius="0dp"
app:cardElevation="0dp">
<RelativeLayout
android:id="@+id/single_notification_row"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="15dp"
android:orientation="horizontal"
android:paddingLeft="15dp"
android:paddingRight="15dp">
<ImageView
android:id="@+id/time_entry_notification_image"
android:layout_width="15dp"
android:layout_height="15dp"
android:layout_centerVertical="true"
android:layout_marginLeft="5dp"
android:src="@drawable/information" />
<TextView
android:id="@+id/single_notification_text"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="45dp"
android:textColor="@color/black_58"
/>
</RelativeLayout>
</android.support.v7.widget.CardView>
</RelativeLayout>
我還添加了Viewflipper。 這是原因嗎? 您可以看到第一個XML具有兩個recycler-view。 一個工作正常,因為該回收者視圖沒有卡片視圖。
嘗試一下
recylerView.setHasFixedSize(true);
recylerView.setNestedScrollingEnabled(false);
關閉recyclerview水平滾動。
LayoutManager layoutManager = new LinearLayoutManager(this,RecyclerView.VERTICAL,false)
{
@override
public Boolean canScrollHorizontally(){
return false;
}
}
recyclerView.setLayout(layoutManager);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.