9

Tôi đang cố gắng thêm Ripple Hiệu ứng vào mục của RecyclerView. Tôi đã có một cái nhìn trực tuyến, nhưng không thể tìm thấy những gì tôi cần. Tôi đã cố gắng android:background thuộc tính đến RecyclerView chính nó và đặt nó vào "?android:selectableItemBackground" nhưng nó đã không làm việc .:Mục Recyclerview nhấp vào hiệu ứng gợn sóng

bố trí Chánh của tôi là như

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:padding="10dp"> 

    <android.support.v7.widget.RecyclerView 
     android:id="@+id/dailyTaskList" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:clickable="true" 
     android:focusable="true" 
     android:scrollbars="vertical" /> 
</LinearLayout> 

và bộ chuyển đổi mẫu này được hiển thị ở bên dưới

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <TextView 
       android:id="@+id/txtTitle" 
       style="@style/kaho_panel_sub_heading_textview_style" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/txtDate" 
       style="@style/kaho_content_small_textview_style" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

    </LinearLayout> 
</LinearLayout> 

Vui lòng cung cấp cho tôi giải pháp

+0

Bạn đã thử cha mẹ nào "android: background ="? Android: attr/selectableItemBackground "'? –

Trả lời

27

Thêm android:background="?attr/selectableItemBackground" để phụ huynh đầu nhất của bố cục mục của bạn nên làm các trick. Tuy nhiên trong một số trường hợp, nó vẫn bỏ lỡ hoạt ảnh, thêm android:clickable="true" làm điều đó.

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?attr/selectableItemBackground" 
    android:orientation="vertical"> 

    <LinearLayout 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:orientation="vertical" 
     android:padding="5dp"> 

     <TextView 
      android:id="@+id/txtTitle" 
      style="@style/kaho_panel_sub_heading_textview_style" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

     <TextView 
      android:id="@+id/txtDate" 
      style="@style/kaho_content_small_textview_style" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" /> 

    </LinearLayout> 
</LinearLayout> 
1

Trong người tái chế của bạnXem mục Phụ huynh, Thêm

android:background="?android:attr/selectableItemBackground" 

Giống như dưới đây:

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:custom="http://schemas.android.com/apk/res-auto" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?android:attr/selectableItemBackground" 
    android:orientation="vertical"> 

     <LinearLayout 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" 
      android:padding="5dp"> 

      <TextView 
       android:id="@+id/txtTitle" 
       style="@style/kaho_panel_sub_heading_textview_style" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 

      <TextView 
       android:id="@+id/txtDate" 
       style="@style/kaho_content_small_textview_style" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 


    </LinearLayout> 

</LinearLayout> 
Các vấn đề liên quan