我正在尝试将Ripple Effect添加到RecyclerView的项目中.我在网上看了一下,但找不到我需要的东西.我认为它必须是自定义效果.我已经尝试了android:background属性到RecyclerView本身并将其设置为"?android:selectableItemBackground"但它没有工作:
<android.support.v7.widget.RecyclerView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:focusable="true"
android:clickable="true"
android:background="?android:selectableItemBackground"
android:id="@+id/recyclerView"
android:layout_below="@+id/tool_bar"/>
Run Code Online (Sandbox Code Playgroud)
这是我试图将效果添加到的RecyclerView:

我很想为我的开源库启用触摸反馈.
我创造了一个RecyclerView和一个CardView.该CardView包含不同的区域不同的onClick动作.现在,如果用户点击卡中的任何位置,我很乐意触发Ripple效果,但我无法实现此行为.
这是我的listitem,您也可以在GitHub上找到它:https://github.com/mikepenz/AboutLibraries/blob/master/library/src/main/res/layout/listitem_opensource.xml
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:background="@drawable/button_rect_normal"/>
<LinearLayout
android:padding="6dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingRight="8dp"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/libraryName"
android:textColor="@color/title_openSource"
android:textSize="@dimen/textSizeLarge_openSource"
android:textStyle="normal"
android:layout_width="0dp"
android:layout_weight="5"
android:layout_height="wrap_content"
android:ellipsize="end"
android:maxLines="1"/>
<TextView
android:id="@+id/libraryCreator"
android:textColor="@color/text_openSource"
android:textStyle="normal"
android:layout_width="0dp"
android:layout_weight="2"
android:layout_height="wrap_content"
android:layout_marginTop="2dp"
android:gravity="right"
android:maxLines="2"
android:textSize="@dimen/textSizeSmall_openSource"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="@color/dividerLight_openSource"/>
<TextView
android:id="@+id/libraryDescription"
android:textSize="@dimen/textSizeSmall_openSource"
android:textStyle="normal"
android:textColor="@color/text_openSource"
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:maxLines="20">
</TextView>
<View
android:id="@+id/libraryBottomDivider"
android:layout_width="match_parent"
android:layout_height="1px"
android:layout_marginTop="4dp"
android:background="@color/dividerLight_openSource"/>
<LinearLayout
android:id="@+id/libraryBottomContainer"
android:gravity="center_vertical"
android:paddingLeft="8dp"
android:paddingTop="4dp"
android:paddingRight="8dp" …Run Code Online (Sandbox Code Playgroud) android touch-feedback android-cardview rippledrawable android-recyclerview
我有一个Recycler View,其中包含从内部存储加载的图像.我想点击时突出显示所选项目.我尝试了很多东西,但它没有用.实际上我需要的是当我点击Recycler View中的任何项目时,Item必须进入My ArrayList,它也应该突出显示,当我点击或说取消选择时它必须再次变为正常.这是我的代码:
public class Images extends Fragment {
private List<ImageHolder> imageList;
Cursor imageCursor;
RecyclerView recyclerView;
MyImageAdapter adapter;
ActionButton clickButton;
List<String> listofImages;
List<Integer> pos;
int columnIndex;
StringBuilder stringBuilder;
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
View rootlayout = inflater.inflate(R.layout.image, container, false);
listofImages=new ArrayList<String>();
pos=new ArrayList<Integer>();
stringBuilder=new StringBuilder();
ContentResolver imageResolver = getActivity().getContentResolver();
Uri imageUri = android.provider.MediaStore.Images.Media.EXTERNAL_CONTENT_URI;
String projection[]={MediaStore.Images.Thumbnails._ID,MediaStore.Images.Media.TITLE};
imageCursor = getActivity().managedQuery(imageUri, projection, null, null, null);
clickButton= (ActionButton) rootlayout.findViewById(R.id.action_button);
recyclerView = (RecyclerView) rootlayout.findViewById(R.id.recycler_view_image);
adapter = new MyImageAdapter(getActivity(), getImageList()); …Run Code Online (Sandbox Code Playgroud) 我想要一个选择器单击状态,以便在其子项之上绘制一个简单的布局.我认为这类似于ListView中的"drawSelectorOnTop"属性.示例布局:
<LinearLayout
android:background="@drawable/my_click_selector">
<LinearLayout
android:background="#F00" />
</LinearLayout>
---------------
| |
| ----------- |
| ----------- |
| |
---------------
Run Code Online (Sandbox Code Playgroud)
所以这里我们有一个父线性布局,一个内部子项具有纯色背景(红色).当我单击父项时,资产的背景颜色会根据我的选择器中的定义而更改,但由于子项在z顺序中更接近用户,因此它保持不变.
有没有办法让选择器选择状态绘制在所有孩子之上而不是在?
谢谢
我有一个CustomListView地方,我正在显示一些文本,并image使用Picasso的库显示.我在xmldrawable文件夹中创建了一个文件,并为drawable-21文件夹创建了一个文件,Ripple Effect但由于某种原因,效果不会超过ImageView.
这是我的文件:
drawable:
listview_item_background.xml
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_pressed="true">
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#ffdadada"/>
</shape>
</item>
<item>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="rectangle" >
<solid
android:color="#ffffff"/>
</shape>
</item>
</selector>
Run Code Online (Sandbox Code Playgroud)
drawable-v21:
listview_item_background.xml
<?xml version="1.0" encoding="utf-8"?>
<ripple xmlns:android="http://schemas.android.com/apk/res/android"
android:color="#ffdadada">
<item android:drawable="@android:color/white"/>
</ripple>
Run Code Online (Sandbox Code Playgroud)
activity_main:
<?xml version="1.0"?>
<android.support.design.widget.CoordinatorLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/app_bar_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsing_toolbar"
android:layout_width="match_parent"
android:layout_height="150dp"
app:layout_scrollFlags="scroll|exitUntilCollapsed"
app:expandedTitleMarginStart="20dp"
app:expandedTitleMarginEnd="20dp"
app:contentScrim="@color/colorPrimary"
android:background="@color/colorPrimary"> …Run Code Online (Sandbox Code Playgroud)