我在Listview内的Cardview在Android L(Nexus 5)中没有显示阴影。 此外,圆形边缘没有正确显示。 这里是Listview的适配器视图的代码: <?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" xmlns:card_view="http://schemas.android.com/apk/res-auto" xmlns:app="http://schemas.android.com/apk/res/com.example.myapp" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" > <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:id="@+id/card_view" android:layout_width="match_parent" android:layout_height="wrap_content" app:cardBackgroundColor="@android:color/white" android:foreground="?android:attr/selectableItemBackground" app:cardCornerRadius="4dp" app:cardElevation="4dp" > <RelativeLayout android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingTop="@dimen/activity_vertical_margin" > <TextView android:id="@+id/tvName" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignParentTop="true" android:layout_marginTop="@dimen/padding_small" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:textAppearance="?android:attr/textAppearanceLarge" /> <ImageView android:id="@+id/ivPicture" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/tvName" android:layout_centerHorizontal="true" android:scaleType="fitCenter" /> <TextView android:id="@+id/tvDetail" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@+id/ivPicture" […]
CardView有一个属性card_view:cardBackgroundColor来定义背景颜色。 这个属性工作正常。 同时还没有一种方法来dynamic改变颜色。 我刚刚尝试过这样的解决scheme: mCardView.setBackgroundColor(…); 或使用cardView内部的布局 <android.support.v7.widget.CardView> <LinearLayout android:id="@+id/inside_layout"> </android.support.v7.widget.CardView> View insideLayout = mCardView.findViewById(R.id.inside_layout); cardLayout.setBackgroundColor(XXXX); 这些解决scheme不起作用,因为该卡具有cardCornerRadius。
我有一个片段,其中包含一个带有layout_width =“match_parent”的RecyclerView: <android.support.v7.widget.RecyclerView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:layout_gravity="center" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity$PlaceholderFragment" /> RecyclerView中的项目也是一个CardView,也是layout_width =“match_parent”: <android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android" 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="match_parent" android:layout_margin="20dp" card_view:cardCornerRadius="4dp"> <TextView android:layout_gravity="center" android:id="@+id/info_text" android:layout_width="match_parent" android:gravity="center" android:layout_height="match_parent" android:textAppearance="?android:textAppearanceLarge"/> </android.support.v7.widget.CardView> 我膨胀的项目视图如下: public MyAdapter.ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) { CardView v = (CardView) LayoutInflater.from(parent.getContext()) .inflate(R.layout.card_listitem, null, true); ViewHolder vh = new ViewHolder(v); return […]
我想要使用新的Android L开发人员预览支持库(如上所述)引入的CardView小部件,它似乎是v7支持库新版本的一部分。 我现在更新了我的SDK版本,下载了最新的支持库软件包,但是我仍然无法find新的CardView小部件。 我已经search了networking和官方的文档,但没有得到任何提示,我可以得到新的支持库。 任何帮助,高度赞赏! 编辑:我正在使用ADT / Eclipse
我试图让CardView在触摸时通过在Android开发者页面上描述的activity activity XML文件中设置android:backgound属性来显示涟漪效应,但是它不起作用。 根本没有animation,但onClick中的方法被调用。 我也尝试创build一个ripple.xml文件,如同这里所build议的,但结果相同。 CardView出现在活动的XML文件中: <android.support.v7.widget.CardView xmlns:card_view="http://schemas.android.com/apk/res-auto" android:layout_width="155dp" android:layout_height="230dp" android:elevation="4dp" android:translationZ="5dp" android:clickable="true" android:focusable="true" android:focusableInTouchMode="true" android:onClick="showNotices" android:background="?android:attr/selectableItemBackground" android:id="@+id/notices_card" card_view:cardCornerRadius="2dp"> </android.support.v7.widget.CardView> 我对android开发比较陌生,所以我可能会犯一些明显的错误。 提前致谢。
任何人都可以向我解释如何实现一些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>
我想在我的项目中使用CardView,但是当我运行我的应用程序时,出现以下错误。 我正在使用Eclipse 。 Error: Error inflating class and android.support.v7.widget.CardView The graphical view of my xml file says 'The following classes could not be instantiated: – android.support.v7.widget.CardView (Open Class, Show Error Log) See the Error Log (Window > Show View) for more details.' 请帮忙。 这是我使用CardView片段的布局 <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" tools:context="com.example.log.MyContactsFragment" > <!– TODO: Update blank […]
我有一个包含RecyclerView (卡片列表)的DialogFragment 。 在这个RecyclerView是一个或多个CardViews可以有任何高度。 我想给这个DialogFragment正确的高度基于CardViews包含在内。 通常这会很简单,我会像这样在RecyclerView上设置wrap_content 。 <android.support.v7.widget.RecyclerView … xmlns:tools="http://schemas.android.com/tools" android:id="@+id/recycler_view" android:layout_width="match_parent" android:layout_height="wrap_content" android:clickable="true" android:scrollbars="vertical" > </android.support.v7.widget.RecyclerView> 因为我正在使用RecyclerView这不起作用,请参阅: https://issuetracker.google.com/issues/37001674 和 嵌套的Recycler视图高度不包裹其内容 在这两个页面上,人们build议扩展LinearLayoutManager并覆盖onMeasure() 我首先使用了第一个链接中提供的LayoutManager : public static class WrappingLayoutManager extends LinearLayoutManager { public WrappingLayoutManager(Context context) { super(context); } private int[] mMeasuredDimension = new int[2]; @Override public void onMeasure(RecyclerView.Recycler recycler, RecyclerView.State state, int widthSpec, int heightSpec) { […]
我想实现一个包含RecyclerView和ScrollView在同一个布局的布局。 布局模板: <RelativeLayout> <ScrollView android:id="@+id/myScrollView"> <unrelated data>…</unrealated data> <android.support.v7.widget.RecyclerView android:layout_width="match_parent" android:layout_height="wrap_content" android:id="@+id/my_recycler_view" /> </ScrollView> </RelativeLayout> 问题:我可以滚动到ScrollView的最后一个元素 我试过的东西: ScrollView里面的卡片视图(现在ScrollView包含RecyclerView ) – 可以看到卡片,直到RecyclerView 最初的想法是实现这个viewGroup使用RecyclerView而不是ScrollView ,其中一个视图types是CardView但我得到了与ScrollView完全相同的结果