2016-04-19 14 views
0

私はrecyclerviewの項目をタッチしたときの波及効果を追加する波及効果

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

を使用しています。 リスト項目を長くクリックすると、アクションバーが表示されます。ただし、その項目は強調表示されません。私が選択した項目を強調するために、背景として

<selector xmlns:android="http://schemas.android.com/apk/res/android"> 
<item android:state_selected="true"> 
    <shape> 
     <solid android:color="@color/selector"/> 
    </shape> 
</item> 

<item android:state_pressed="true"> 
    <shape> 
     <solid android:color="@color/selector"/> 
    </shape> 
</item> 

<item> 
    <shape> 
     <solid android:color="@android:color/transparent"/> 
    </shape> 
</item> 
</selector> 

セレクタを持っていたが、私はselectableItemBackgroundのもののために行っているリップルアニメーションを持っていると思ったので。 リプルファイルを21個のファイル拡張子を持つフォルダに書き込む方法を示す記事があります。ただし、リップルタグはAPIレベル21以上でのみ使用できます。私はセレクタ21とそれ以上のものよりも明るいデバイスカバレッジを持っていたいので、私のセレクタとリップルのものとを組み合わせる別のものがあるかどうかはわかりませんでした。私はでframeLayoutを使用して私の問題を解決するために素敵なトリックを発見した

おかげ

答えて

0

。次のように

recyclerview項目のレイアウトが見える:

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

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="?android:attr/listPreferredItemHeight" 
    android:background="@drawable/selector" 
    android:orientation="vertical"> 

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="match_parent" 
        android:layout_height="0dp" 
        android:layout_marginLeft="@dimen/activity_horizontal_margin" 
        android:layout_weight="1" 
        android:gravity="center_vertical" 
        android:orientation="vertical"> 

     <TextView 
      android:id="@+id/name" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ellipsize="marquee" 
      android:singleLine="true" 
      android:textColor="@color/modelTitelColor" 
      android:textStyle="bold"/> 

     <TextView 
      android:id="@+id/objects" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:ellipsize="marquee" 
      android:singleLine="true" 
      android:textColor="@color/cardview_background" 
      android:textStyle="normal"/> 
    </LinearLayout> 


    <View 
     android:layout_width="match_parent" 
     android:layout_height="1dp" 
     android:background="?android:attr/listDivider"/> 
</LinearLayout> 

<View 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="?android:attr/selectableItemBackground"/> 
</FrameLayout> 

トリックは、内側のLinearLayoutの背景としてセレクタを設定することとでframeLayout内のビューのための有名selectedItemBackgroundを使用することです。

関連する問題