2017-01-19 1 views
0

나는 3 가지 일반 카드보기를 만드는 방법은 무엇입니까?

내가 하나 만들 관리 .. 각 등 같은 신장, 체중이 3 cardviews을 만들려고 해요 :

<?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> 

내가이 cardview의 두 개 더 필요합니다,하지만 난

내가 모든 차를위한 상대 레이아웃과 같은 기본 레이아웃을 생성해야합니까 "여러 루트 태그"오류

을 받고 dviews?

+0

이 XML 파일에 하나 개 이상의 루트 요소가 있음을 의미한다. 맨 위에있는 레이어에는 하나의 요소 만있을 수 있습니다. 이 오류가 다른 XML 파일에 있습니까? 아니면이 파일에 있습니까? 이 중 하나가 올바른 것 같습니다. – DeeV

+0

동일한 레이아웃 파일에 다른 카드보기를 추가하려고하십니까? 그렇다면 다른 레이아웃 안에 배치해야하지만, 반드시 말한 것처럼 RelativeLayout 일 필요는 없습니다. –

답변

0
<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> 
0

cardView 요소를 LinearLayout 또는 다른 레이아웃보기에 만들도록하십시오. 예 :

<?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" ....... 
0

CardView를 넣으려면 루트보기가 필요합니다. 당장 당신은 하나의 CardView를 다른 카드 안에 넣고 있습니다. (왜냐하면 당신의 루트는 CardView입니다). LinearLayout 안에 넣어 봅니다.

<LinearLayout> 
    <CardView> 
    <CardView> 
    <CardView> 
</LinearLayout> 
관련 문제