5

RecyclerViewのアイテムを押したときにタッチフィードバックまたはリップルが表示されますが、機能していないように見えます。RecyclerViewアイテムにチェックボックスが表示されているときに波紋/タッチのフィードバックが表示されない

リップルは長い押しでのみ表示されますが、簡単なプレスでは表示されません。

誰かが私にそれを修正するのを手伝ってもらえますか?前もって感謝します。

PD:ListViewを使用していて、アイテムレイアウトの親がLinearLayoutでした。波紋はうまくいきました。 RecyclerViewに移動した後、項目の波紋は機能しません。私はLinearLayoutをもう一度試しましたが、まだ動作していません。

は、ここであなたがandroid:background="?android:attr/selectableItemBackground"使用レイアウトファイル

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout 
    android:id="@+id/requestCard" 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:background="?android:attr/selectableItemBackground" 
    android:clickable="true" 
    android:focusable="true" 
    android:descendantFocusability="blocksDescendants" 
    android:orientation="horizontal"> 

    <ImageView 
     android:id="@+id/imgIcon" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:adjustViewBounds="true" 
     android:maxHeight="64dp" 
     android:maxWidth="64dp" 
     android:padding="@dimen/lists_padding" 
     android:src="@drawable/ic_launcher" 
     tools:ignore="ContentDescription"/> 

    <TextView 
     android:id="@+id/txtName" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_centerVertical="true" 
     android:layout_toEndOf="@+id/imgIcon" 
     android:layout_toRightOf="@+id/imgIcon" 
     android:ellipsize="end" 
     android:maxLength="@integer/request_text_length" 
     android:maxLines="1" 
     android:padding="@dimen/lists_padding" 
     android:textSize="@dimen/abc_text_size_large_material" 
     tools:text="App Name"/> 

    <CheckBox 
     android:id="@+id/chkSelected" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:layout_alignParentEnd="true" 
     android:layout_alignParentRight="true" 
     android:layout_centerVertical="true" 
     android:clickable="false" 
     android:padding="@dimen/lists_padding"/> 

</RelativeLayout> 
+0

アンドロイドを追加:descendantFocusability = "blocksDescendants"アイテムのルート要素。 –

+0

@GabrieleMariottiは既にしました。まだ動かない。更新されたレイアウトファイル。 –

+0

私は確信していませんが、ビューグループのビューが波紋効果をカバーするため、これが起こる可能性があります。だからそこにはありますが、見ることはできません。リップル専用の特別なビュー(幅と高さはmatch_parent)を追加することになりました。試してみてください。 –

答えて

8

を使用する必要があります。

notifyDataSetChanged()は、デフォルトのリップル エフェクトと競合します。私はあなたがリップルeffect.Iを探していると思う

new recyclerAdapter.ClickListener() { 
    @Override 
    public void onClick(int position) { 

     ... awesome item onClick code ... 

     notifyItemChanged(position); 
     //notifyDataSetChanged(); <//--- Causes the no ripple bug 
    } 
}; 
0

だけど、あなたはnotifyItemChanged(position)後ないコールnotifyDataSetChanged()を行うを確認して、(自分のコールバックで想定して)あなたのonClickメソッドでandroid:foreground="?android:attr/selectableItemBackground"

+0

既に試しました。まだ動かない。 –

+0

私はテストプロジェクトであなたのレイアウトを試してみましたが、すべて正常に動作します - https://drive.google.com/file/d/0B5KouoPaI5qqQWFRenVpRkRlQ3M/view?usp=sharing – curioushikhov

+0

@curioshikhov私は同じレイアウトを試しましたが、まだ何も得ていません...あなたに連絡して助けてくれる場所がありますか?プライベートなので、私は完全なソースを共有することはできませんが、もしあなたが助けてくれるなら、事前に感謝してください。 –

1

だけ

<?xml version="1.0" encoding="utf-8"?> 
<ripple xmlns:android="http://schemas.android.com/apk/res/android" 
    android:color="?attr/colorControlHighlight"> 
    <item 
     android:id="@android:id/mask" 
     android:drawable="@android:color/white" 
     > 

    </item> 
</ripple> 

&の内側に描画可能&書き込みにこのコードを1つのXMLファイル(ripple.xml)を作成し、あなたの基本的な考え方を与えることができます単にrecyclerview要素を宣言した別のxmlファイルに2行書きます。

android:background="@drawable/ripple" 
android:clickable="true" 

などは私の場合、私は唯一のTextViewを持っていますし、親タグで、私はこの2行

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:orientation="vertical" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:background="@drawable/ripple" 
    android:clickable="true" 
    > 

<TextView 
    android:id="@+id/textView_Username" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:textSize="30sp" 
    android:textColor="@color/colorPrimary" 
    android:layout_marginLeft="10dp" 
    android:layout_marginTop="10dp" 
    /> 
</LinearLayout> 

最後に結果を宣言しています:enter image description here

このビデオ

https://www.youtube.com/watch?v=qvVkDb7DqCkを参照してくださいに

関連する問題