新しい 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 に答える