2017-09-14 29 views
2

我正在使用RecyclerView來顯示引用列表片段。我試圖在列表項中使用紋波效果,但它不起作用。我RecyclerView就像下面RecyclerView中沒有紋波效應

<android.support.v7.widget.RecyclerView 
     android:id="@+id/listQuoteView" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:background="?attr/BackColor" 
     android:layout_above="@+id/startAppBanner" 
     android:layout_alignParentTop="true" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentStart="true" /> 

和列表項XML是像下面

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:app="http://schemas.android.com/apk/res-auto" 
    android:background="?attr/selectableItemBackground" 
    android:clickable="true" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"> 


    <android.support.v7.widget.CardView 

     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="4dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginTop="4dp" 
     app:cardCornerRadius="6dp" 
     app:cardElevation="4dp"> 

     <LinearLayout 
      android:id="@+id/quoteActionView" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:background="?attr/TextColor" 
      android:clickable="true" 
      android:orientation="horizontal"> 

      <ImageView 
       android:id="@+id/imageAuthorView" 
       android:layout_width="@dimen/imageAuthorView" 
       android:layout_height="@dimen/imageAuthorView" 
       android:visibility="visible" /> 



      <LinearLayout 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 
       android:layout_gravity="center" 
       android:orientation="vertical"> 

       <TextView 
        android:id="@+id/textQuote" 
        android:ellipsize="end" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:paddingRight="@dimen/list_text_margin" 
        android:paddingLeft="@dimen/list_text_margin" 
        android:gravity="center_vertical" 
        android:layout_weight="2" 
        android:maxLines="2" 
        android:layout_margin="2dp" 
        android:lineSpacingExtra="@dimen/linespace" 
        android:textColor="?attr/MainTextColor" 
        android:text="Hello there two line text for show here which I am typing for a test" 
        android:scrollHorizontally="true" 
        android:textSize="@dimen/textDetailQuote" 
        android:textStyle="bold" /> 

       <LinearLayout 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:gravity="center" 
        android:background="?attr/dark_color" 
        android:orientation="horizontal"> 

        <ImageView 
         android:layout_width="@dimen/likeIcon" 
         android:layout_height="@dimen/likeIcon" 
         android:layout_weight="1" 
         android:tint="?attr/List_Text" 
         android:src="@drawable/time_new_ic" /> 

        <TextView 
         android:id="@+id/lblTimeCount" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="2" 
         android:text="00:00" 
         android:textStyle="bold" 
         android:textColor="?attr/List_Text" 
         android:textSize="@dimen/lblTime" /> 



        <ImageView 
         android:layout_width="@dimen/likeIcon" 
         android:layout_height="@dimen/likeIcon" 
         android:layout_weight="1" 
         android:tint="?attr/List_Text" 
         android:src="@drawable/fav_new_ic" /> 

        <TextView 
         android:id="@+id/lblLikeCount" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:text="200" 
         android:textStyle="bold" 
         android:textColor="?attr/List_Text" 
         android:textSize="@dimen/lblTime" /> 

        <ImageView 
         android:layout_width="@dimen/likeIcon" 
         android:layout_height="@dimen/likeIcon" 
         android:layout_weight="1" 
         android:tint="?attr/List_Text" 
         android:src="@drawable/share_new_ic" /> 

        <TextView 
         android:id="@+id/lblShareCount" 
         android:layout_width="wrap_content" 
         android:layout_height="wrap_content" 
         android:layout_weight="1" 
         android:textStyle="bold" 
         android:text="100" 
         android:textColor="?attr/List_Text" 
         android:textSize="@dimen/lblTime" /> 

       </LinearLayout> 

      </LinearLayout> 

     </LinearLayout> 

    </android.support.v7.widget.CardView> 


</RelativeLayout> 

我曾嘗試在計算器列舉了大量的解決方案,但沒有任何工作。 I f我從List Item中移除Cardview ....在LinearLayout後面顯示Ripple效果,但我也想使用Cardview。讓我知道是否有人可以幫我解決這個問題。謝謝

注:我已經解決了它使用this solution。由於

+0

使您的卡式點擊,並給它forgroundColor –

回答

1

創建紋波繪製並將其設置爲你的佈局前景

ripple.xml

<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:color="@color/your_color" 
    tools:targetApi="lollipop"> 
    <item android:id="@android:id/mask"> 
     <shape android:shape="rectangle"> 
      <solid android:color="@color/your_color" /> 
     </shape> 
    </item> 
</ripple> 

改變這樣的代碼:

<RelativeLayout 
    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"> 


    <android.support.v7.widget.CardView 
     android:clickable="true" 
     android:foreground="@drawable/ripple" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginBottom="4dp" 
     android:layout_marginLeft="8dp" 
     android:layout_marginRight="8dp" 
     android:layout_marginTop="4dp" 
     app:cardCornerRadius="6dp" 
     app:cardElevation="4dp"> 
+0

嗨!謝謝,但它不工作:( – Priya

+0

嘗試它作爲前景。我試圖通過設置相同的代碼作爲前景它爲我工作 –

+0

看到我的更新的答案設置漣漪cardview不是相對佈局@Priya –

1

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

+0

它仍然不工作....以及我想使用自定義顏色等。謝謝 – Priya

1

設置紋波爲前景繪製的CardView

android:foreground="?attr/selectableItemBackground" 

這將允許紋波露面以上CardView裏面的內容,這通常是你想要的一個CardView

+0

嗨!謝謝但不能正常工作 – Priya

+0

你在CardView或RelativeLayout上應用了它嗎?它只適用於CardView。 –