LoginSignup
7
10

More than 5 years have passed since last update.

AndroidのRecycleViewでrippleエフェクトが出ない時にチェックしたほうがいいこと

Last updated at Posted at 2017-04-14

自分でかつて解決したのに再び自分でハマったので覚書。
なんでこれで直るのかは特に調べてないです(以前調べた気がするけど忘れた)→LinearLayoutのandroid:foregroundの提供APIレベルが23からなのが原因っぽい(Referenceはレベル1と書かれてるらしい)。
なのでLinearLayoutにタグを指定しても動かない(MinSDKを23以上にしてもいいけど普及率を考えるとあまり現実的じゃない)。
一方でFrameLayoutではandroid:foregroundはレベル1から提供されてるので動いた、というのがからくり。

rippleエフェクトが出ないxmlの書き方

ripple_ng_adapter.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
              android:orientation="vertical"
              android:focusable="true"
              android:clickable="true"
              android:foreground="?android:attr/selectableItemBackground"
              android:layout_width="match_parent"
              android:layout_height="wrap_content">
    <!-- 中身 -->
</LinearLayout>

rippleエフェクトの指定したXMLタグの中にAdapterの要素が実装されてる

rippleエフェクトがでるxmlの書き方

ripple_ok_adapter.xml
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="match_parent"
             android:focusable="true"
             android:clickable="true"
             android:layout_height="wrap_content"
             android:foreground="?android:attr/selectableItemBackground">
    <LinearLayout android:orientation="vertical"
                  android:layout_width="match_parent"
                  android:layout_height="wrap_content">
    <!-- 中身 -->
    </LinearLayout>
</FrameLayout>

rippleエフェクトがFrameLayoutに指定されてて、その中にLinerLayoutを指定し、Adapterの主要素が実装されている

7
10
2

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
7
10