简体   繁体   English

如何创建3个通用卡片视图?

[英]How to create 3 generic card views?

I'm trying to create 3 cardviews, each have the same height, weight etc.. 我正在尝试创建3个cardview,每个都有相同的高度,重量等。

I managed to create one: 我设法创建了一个:

    <?xml version="1.0" encoding="utf-8"?>
<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/card_view"
    android:layout_width="match_parent"
    android:layout_height="200dp"
    android:layout_margin="8dp"
    android:padding="8dp">

  <RelativeLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent">

    <ImageButton
        android:id="@+id/button"
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:layout_alignParentTop="true"
        android:scaleType="centerInside"
        android:src="@drawable/moon20"
        android:background="@android:color/white"
        android:padding="8dp"/>

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:maxLines="3"
        android:padding="8dp"
        android:text="20 min Power Nap"
        android:textColor="@color/colorSecondaryText"
        android:textStyle="bold"
        android:textSize="20dp"
        android:textAlignment="center"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        />


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

I need two more of this cardview, but I'm getting 我需要这张卡视图中的另外两个,但我得到了

"multiple root tag" error “多个根标签”错误

Do I have to create a base layout like Relative layout for all cardviews? 是否必须为所有卡片视图创建基本布局(如相对布局)?

Try to make your cardView element inside a LinearLayout or some other Layout views. 尝试使您的cardView元素位于LinearLayout或其他一些Layout视图中。 example: 例:

   <?xml version="1.0" encoding="utf-8"?>

   <LinearLayout
       android:layout_width="match_parent"
       android:layout_height="match_parent" >

       <android.support.v7.widget.CardView       
       xmlns:android="http://schemas.android.com/apk/res/android"  .......

You need a root view to put inside your CardViews. 您需要一个根视图才能放入CardViews。 Right now you are putting one CardView inside the other (Because your root is a CardView). 现在,您将一个CardView放在另一个CardView中(因为您的根是CardView)。 Try to put them inside a LinearLayout. 尝试将它们放在LinearLayout中。

<LinearLayout>
     <CardView>
     <CardView>
     <CardView>
</LinearLayout>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    xmlns:android="http://schemas.android.com/apk/res/android"
    >

     <CardView>
     <CardView>
     <CardView>
</LinearLayout>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM