对 recyclerview 触摸事件没有连锁反应
No ripple effect on recycleview touch event
我已经使用 RecycleView
实现了导航抽屉,但是当我点击项目时,没有显示涟漪效果。我的设备是 运行 API 22.
fragment_navigation.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_alignParentTop="true"
android:background="@color/colorPrimary">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/ic_profile"
android:scaleType="fitCenter"
android:layout_centerInParent="true" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_marginTop="15dp" />
</RelativeLayout>
我的行是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@android:drawable/ic_input_get" android:id="@+id/imageView"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingTop="10dp"
android:text="asa"
android:paddingBottom="10dp"
android:textSize="15dp"
android:textStyle="bold"
android:layout_alignParentTop="true" android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView"/>
</RelativeLayout>
这是什么问题,我该如何解决?
试试这个作为你的行布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@android:drawable/ic_input_get"
android:id="@+id/imageView"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingTop="10dp"
android:text="asa"
android:paddingBottom="10dp"
android:textSize="15dp"
android:textStyle="bold"
android:layout_toRightOf="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/imageView"/>
</RelativeLayout>
我已经使用 RecycleView
实现了导航抽屉,但是当我点击项目时,没有显示涟漪效果。我的设备是 运行 API 22.
fragment_navigation.xml:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@android:color/white">
<RelativeLayout
android:id="@+id/nav_header_container"
android:layout_width="match_parent"
android:layout_height="140dp"
android:layout_alignParentTop="true"
android:background="@color/colorPrimary">
<ImageView
android:layout_width="70dp"
android:layout_height="70dp"
android:src="@drawable/ic_profile"
android:scaleType="fitCenter"
android:layout_centerInParent="true" />
</RelativeLayout>
<android.support.v7.widget.RecyclerView
android:id="@+id/drawerList"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/nav_header_container"
android:layout_marginTop="15dp" />
</RelativeLayout>
我的行是:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true">
<ImageView android:layout_width="wrap_content" android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@android:drawable/ic_input_get" android:id="@+id/imageView"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingTop="10dp"
android:text="asa"
android:paddingBottom="10dp"
android:textSize="15dp"
android:textStyle="bold"
android:layout_alignParentTop="true" android:layout_toRightOf="@+id/imageView"
android:layout_toEndOf="@+id/imageView"/>
</RelativeLayout>
这是什么问题,我该如何解决?
试试这个作为你的行布局
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="?android:attr/selectableItemBackground"
android:focusable="true"
android:clickable="true">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@android:drawable/ic_input_get"
android:id="@+id/imageView"/>
<TextView
android:id="@+id/title"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp"
android:paddingTop="10dp"
android:text="asa"
android:paddingBottom="10dp"
android:textSize="15dp"
android:textStyle="bold"
android:layout_toRightOf="@+id/imageView"
android:layout_alignParentTop="true"
android:layout_toEndOf="@+id/imageView"/>
</RelativeLayout>