我有一个运行新 Appcompat V21 的应用程序,以及一个带有基本列表视图的主要活动。是否可以将此基本列表视图转换为卡片视图,每张卡片上都有图像和标题?(以 Google+ 应用为例)
问问题
1950 次
2 回答
1
是的,实际上很容易做到这一点。由于您已经在使用 v21 的支持库,您只需将基本列表项代码包装在 CardView 中即可。像这样的东西...
<?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"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center"
card_view:cardCornerRadius="4dp"
card_view:contentPadding="8dp">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:id="@+id/title"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/image"
android:gravity="center_vertical"
android:text="Example application"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
于 2015-01-07T07:18:24.180 回答
0
您需要将 recyclerView 与自定义适配器一起使用。
于 2014-12-13T20:22:13.680 回答