2016-07-25 57 views
0

我想要四張卡片。我想要前兩張卡片彼此相鄰水平對齊,然後兩張卡片需要位於下方,並且水平對齊。卡片沒有正確對齊

我使用兩個單獨的LinearLayout,每行用於兩行卡(即每行兩個卡)。

問題是隻有前兩張牌是可見的而另外兩張牌是不可見的。

XML代碼

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:orientation="vertical" 
    tools:context=".MainActivity" 
    android:background="#bcd4d4" 
    android:weightSum="1"> 
    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     android:layout_marginTop="20dp" 
     > 
    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view1" 
     android:layout_width="180" 
     android:layout_height="200dp" 
     card_view:cardCornerRadius="10dp" 
     android:foregroundGravity="center" 
     android:layout_marginBottom="20dp" 
     card_view:cardElevation="15dp" 
     card_view:cardBackgroundColor="#52bf90" 
     card_view:cardUseCompatPadding="true" 
     android:onClick="missed" 

     > 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:hint="MISSED" 
      android:textSize="35sp" 
      android:textAllCaps="true" 
      android:textAlignment="gravity" 
      android:layout_marginTop="40dp" 
      > 

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

    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view2" 
     android:layout_width="180dp" 
     android:layout_height="200dp" 
     card_view:cardCornerRadius="10dp" 
     android:foregroundGravity="center" 
     card_view:cardElevation="15dp" 
     card_view:cardBackgroundColor="#52bf90" 
     card_view:cardUseCompatPadding="true" 
     android:onClick="received" 
     > 

     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:hint="RECEIVED" 
      android:textSize="30sp" 
      android:textAllCaps="true" 
      android:layout_marginTop="40dp" 
      > 
     </TextView> 

     <!--/>--> 
    </android.support.v7.widget.CardView> 
    </LinearLayout> 

    <LinearLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:orientation="horizontal" 
     > 
    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view3" 
     android:layout_width="180dp" 
     android:layout_height="200dp" 
     card_view:cardCornerRadius="10dp" 
     android:foregroundGravity="center" 

     card_view:cardElevation="15dp" 
     card_view:cardBackgroundColor="#52bf90" 
     card_view:cardUseCompatPadding="true" 
     android:onClick="dialled" 
     > 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:hint="DIALLED" 
      android:textSize="40sp" 
      android:textAllCaps="true" 
      android:layout_marginTop="40dp" 
      > 
     </TextView> 

    </android.support.v7.widget.CardView> 
    <android.support.v7.widget.CardView 
     xmlns:card_view="http://schemas.android.com/apk/res-auto" 
     android:id="@+id/card_view4" 
     android:layout_width="180dp" 
     android:layout_height="200dp" 
     card_view:cardCornerRadius="10dp" 
     android:foregroundGravity="center" 

     card_view:cardElevation="15dp" 
     card_view:cardBackgroundColor="#52bf90" 
     card_view:cardUseCompatPadding="true" 
     android:onClick="stats" 
     > 
     <TextView 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:hint="STATS" 
      android:textSize="40sp" 
      android:layout_marginTop="40dp" 
      android:textAllCaps="true" 
      > 
     </TextView> 
    </android.support.v7.widget.CardView> 
</LinearLayout> 

回答

2

您需要將LinerLayout的方向設置爲horizontallayout_heightwrap_content

就像下面這樣。

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal" 
    android:layout_marginTop="20dp"> 
+0

你是right.Thanks – a874