I have a need to display three cards in horizontal order, one after the other. The cards should fill the whole width of the screen. I wanted to use the CardView
that was introduced with Android L
. But I don't know how to display the cards horizontally . Don't know if that's even possible.
Has anyone experimented more with this CardView and can give me some advice?
I don't see the problem. The CardView
is just another View and can easily be wrapped inside a LinearLayout
. So in your case create a LinearLayout, set the orientation
to horizontal
, weightSum
to 3 and put your CardViews inside those Root-Layout and your done.
As an example:
<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>
Which would look like this:
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.