对包含ImageView的RecyclerView项目产生连锁反应

Bin*_*abu 42 android ripple android-recyclerview

我有一个RecyclerView扩展以下网格项:

<RelativeLayout
    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:layout_marginLeft="@dimen/children_tile_border"
    android:layout_marginTop="@dimen/children_tile_border"
    android:clickable="true"
    android:focusable="true"
    android:background="?selectableItemBackground"
    tools:ignore="RtlHardcoded">

        <com.example.app.ui.widget.SquareImageView
            android:id="@+id/child_picture"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:visibility="visible"
            android:layout_alignParentBottom="true"/>

        <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="68dp"
            android:background="@color/tile_text_background"
            android:gravity="center_vertical"
            android:layout_alignParentBottom="true">

            ..............
        </LinearLayout>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)

但除非我将SquareImageView's可见性设置为不可见,否则不会出现涟漪效应.似乎涟漪效应低于SquareImageView.我怎么能把它画成SquareImageView

Jin*_*inu 66

将以下代码添加到父布局中

android:clickable="true"
android:focusable="true"
android:background="?attr/selectableItemBackground" 
Run Code Online (Sandbox Code Playgroud)

如果你想要自定义涟漪效果,请在你的drawable-v21中添加这个ripple_custom.xml

<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
    android:color="@color/colorHighlight">

    <item
        android:id="@android:id/mask"
        android:drawable="@color/windowBackground" />
</ripple>
Run Code Online (Sandbox Code Playgroud)

支持旧版本在drawable中添加ripple_custom.xml

<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
    <item android:state_pressed="true">
        <shape android:shape="rectangle">
            <solid android:color="@color/colorHighlight" />
        </shape>
    </item>
    <item>
        <shape android:shape="rectangle">
            <solid android:color="@android:color/transparent" />
        </shape>
    </item>
</selector>
Run Code Online (Sandbox Code Playgroud)

  • 不适合我.我有一个具有上述配置的RelativeLayout项目根目录:http://pastebin.com/fy3RcfCm,使用android支持库v23 (2认同)

Enz*_*kie 12

更改:

android:background="?selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)

至:

android:background="?android:attr/selectableItemBackground"
Run Code Online (Sandbox Code Playgroud)

并将其添加到SquareImageView中

android:clickable="false" 
Run Code Online (Sandbox Code Playgroud)


Sag*_*han 8

我们可以在里面包装RecyclerView Item FrameLayoutandroid:foreground为它设置属性.结帐以下链接了解详情.它非常适合我.