我很想为我的开源库启用触摸反馈.
我创造了一个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
任何人都可以向我解释如何在CardView中实现Google I/O 2014中展示的一些视觉触摸反馈.
以下是我在XML中使用CardView的方法,可能有一些我想念的小东西,所以我只是想知道是否有人可以帮助我?
<!-- A CardView -->
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/CardView_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
card_view:cardCornerRadius="4dp"
android:elevation="2dp">
<LinearLayout
android:id="@+id/LinearLayout_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:onClick="RunSomeMethod"">
<!-- Main CardView Content In Here-->
</LinearLayout> </android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud) android android-layout android-cardview android-5.0-lollipop
我有一个CardView圆角,我希望有一个ImageView顶部,如下面的材料设计指南中的示例所示.

<android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
card_view:cardCornerRadius="4dp">
<!-- ... -->
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
然后在里面CardView我有这个ImageView
<ImageView
android:id="@+id/imageView"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentTop="true"
android:scaleType="centerCrop"
android:src="@drawable/default_cover" />
Run Code Online (Sandbox Code Playgroud)
如果我有card_view:cardCornerRadius设置,0dp那么ImageView卡就像我想要的那样.

但是,材料设计指南规定卡片应有圆角,而不是方角.
我遇到的问题是当我设置card_view:cardCornerRadius其他东西时 0dp,例如4dp,然后发生以下情况:

可以看出,ImageView它不适合CardView.
我的问题是,我怎样才能使它ImageView适合CardView圆角时的布局.
我正在使用android:paddingLeft并android:paddingTop为新CardView窗口小部件设置填充但它不起作用.
我可以为其中的所有控件设置余量CardView作为变通方法,但如果控件太多,那就太痛苦了.
如何为新的cardview小部件设置填充?
<android.support.v7.widget.CardView
xmlns:card_view="http://schemas.android.com/apk/res-auto"
android:id="@+id/card_view"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="200dp"
android:paddingLeft="20dp"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="20dp"
android:paddingBottom="@dimen/activity_vertical_margin"
card_view:cardCornerRadius="2dp">
<TextView
android:id="@+id/info_text"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Hello World!"/>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud) 我想使用已与新的Android L移动开发者预览版支持库介绍(如提到的新CardView小部件在这里),这似乎是V7支持库的一个新版本的一部分.
我现在更新了我的SDK版本,下载了最新的Support Library软件包,但我仍然找不到新的CardView小部件.
我已经搜索了网络和官方文档,但无法获得有关我可以获得新支持库的任何提示.
任何帮助都非常感谢!
编辑:我正在使用ADT/Eclipse
我有一个RecyclerView在里面CardView.该CardView有500dp的高度,但我想缩短这个高度,如果RecyclerView是较小的.所以我想知道RecyclerView在第一次完成放置项目时是否有任何监听器被调用,从而可以将RecyclerView高度设置为CardView高度(如果小于500dp).
简单来说:
我们如何定义CardView的cardBackgroundColor属性的颜色状态(在这种情况下,在ListView布局中)?
(我在安装了4.4的手机上使用了Android L开发者预览版的RC1,在build.gradle中使用了"com.android.support:cardview-v7:21.0.0-rc1")
更长:
在CardView布局中,我们通过cardCornerRadius和cardBackgroundColor设置CardView的角半径和背景颜色.
但是,例如,背景颜色不会被视为选择状态,即是否按下了列表项.
但是,如果在CardView的内部视图中设置了背景颜色和相关的状态,则它将显示在您在CardView中定义的角上.
那么,我们如何才能确保CardView的cardBackgroundColor中的状态得到尊重?
这是cardBackgroundColor,colour_with_states.xml使用的颜色:
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:state_focused="true" android:state_enabled="false" android:state_pressed="true" android:color="@android:color/holo_green_dark" />
<item android:state_focused="true" android:state_enabled="false" android:color="@android:color/holo_green_dark" />
<item android:state_focused="true" android:state_pressed="true" android:color="@android:color/holo_green_dark" />
<item android:state_focused="false" android:state_pressed="true" android:color="@android:color/holo_green_dark" />
<item android:state_focused="true" android:color="@android:color/holo_green_dark" />
<!-- Only this below is seen in the cardview dispaly -->
<item android:color="@android:color/holo_blue_bright" />
</selector>
Run Code Online (Sandbox Code Playgroud)
以及使用CardView的布局:
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:cardview="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
cardview:cardCornerRadius="10dp"
cardview:cardBackgroundColor="@color/colour_with_states"
>
<!-- If we set a background color below, it will overwrite our radius defined above -->
<TextView
xmlns:android="http://schemas.android.com/apk/res/android" …Run Code Online (Sandbox Code Playgroud) 您好我正在使用演示应用程序,我正在使用支持库的卡片视图.默认情况下,它会在它周围添加阴影.我想删除这个阴影,看起来应该很简单.
我试过这个对我不起作用.
CardView cardView = (CardView) v.findViewById(R.id.cardView);
cardView.setElevation(0);
Run Code Online (Sandbox Code Playgroud)
做完这些之后我就崩溃了
11-06 15:12:17.018: E/AndroidRuntime(24315): FATAL EXCEPTION: main
11-06 15:12:17.018: E/AndroidRuntime(24315): Process: com.xyz, PID: 24315
11-06 15:12:17.018: E/AndroidRuntime(24315): java.lang.NoSuchMethodError: android.support.v7.widget.CardView.setElevation
11-06 15:12:17.018: E/AndroidRuntime(24315): at com.xyz.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:85)
11-06 15:12:17.018: E/AndroidRuntime(24315): at com.xyz.adapters.RecycleViewAdapter.onCreateViewHolder(RecycleViewAdapter.java:1)
11-06 15:12:17.018: E/AndroidRuntime(24315): at android.support.v7.widget.RecyclerView$Adapter.createViewHolder(RecyclerView.java:2915)
11-06 15:12:17.018: E/AndroidRuntime(24315): at android.support.v7.widget.RecyclerView$Recycler.getViewForPosition(RecyclerView.java:2511)
11-06 15:12:17.018: E/AndroidRuntime(24315): at android.support.v7.widget.LinearLayoutManager$RenderState.next(LinearLayoutManager.java:1425)
11-06 15:12:17.018: E/AndroidRuntime(24315): at android.support.v7.widget.LinearLayoutManager$RenderState.next(LinearLayoutManager.java:1425)
Run Code Online (Sandbox Code Playgroud)
layout.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:card_view="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/apk/res/com.xyz"
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="5dp"
android:layout_marginLeft="5dp"
android:layout_marginRight="5dp"
android:orientation="horizontal" >
Run Code Online (Sandbox Code Playgroud)
提前致谢.
在xml中,我经常这样做来模拟onClick效果:
<android.support.v7.widget.CardView
android:id="@+id/cardView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:foreground="?selectableItemBackground">
...
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
有没有办法?selectableItemBackground在java中访问?
我正在试验支持库的recyclerview和卡片.我有回收卡的卡片.每张卡片的右上角都有一个"x"图标可将其删除:
该卡的xml, list_item.xml:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="5dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:id="@+id/taskDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:textSize="40sp"
android:text="hi"/>
<ImageView
android:id="@+id/xImg"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:src="@drawable/ic_remove"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
Run Code Online (Sandbox Code Playgroud)
我试图用我会在使用的位置标记的行notifyItemRemoved(position)中TaskAdapter.java:
public class TaskAdapter extends RecyclerView.Adapter<TaskAdapter.TaskViewHolder> {
private List<Task> taskList;
private TaskAdapter thisAdapter = this;
// cache of views to reduce number of findViewById calls
public static class TaskViewHolder extends RecyclerView.ViewHolder implements View.OnClickListener {
protected TextView taskTV;
protected ImageView closeBtn;
public TaskViewHolder(View v) {
super(v); …Run Code Online (Sandbox Code Playgroud) android android-support-library android-cardview android-recyclerview