0

3 枚のカードを横に並べて表示する必要があります。カードは画面の幅全体を埋める必要があります。CardViewで導入された を使用したかったのAndroid Lです。しかし、カードを横に並べる方法がわかりません。それが可能かどうかもわかりません。
誰かがこの CardView をもっと試してみて、アドバイスをくれますか?

4

1 に答える 1

3

問題がわかりません。はCardView単なる別のビューであり、 内に簡単にラップできますLinearLayout。したがって、あなたのケースでは LinearLayout を作成し、orientationtoを 3 に設定し、CardViews をそれらの Root-Layout 内に配置して完了です。horizontalweightSum

例として:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:prefix="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:weightSum="3">

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_weight="1"
        prefix:cardCornerRadius="4dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:padding="16dp"
            android:text="CardView1" />

    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_weight="1"
        prefix:cardCornerRadius="4dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:padding="16dp"
            android:text="CardView2" />

    </android.support.v7.widget.CardView>

    <android.support.v7.widget.CardView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_marginBottom="16dp"
        android:layout_weight="1"
        prefix:cardCornerRadius="4dp">

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:padding="16dp"
            android:text="CardView3" />

    </android.support.v7.widget.CardView>

</LinearLayout>

これは次のようになります。

LinearLayout の CardView

于 2014-09-18T14:58:59.213 に答える