2016-07-22 6 views
0

Ich versuche, über Kartenansicht zu lernen.Ich schrieb einen einfachen Code, um zwei Karten zu sehen.Aber das Problem ist, dass die zweite Karte nicht sichtbar ist.Ich denke, dass die erste Karte mit übereinstimmt die zweite Karte, deshalb ist die zweite Karte nicht sichtbar.Karten übereinander über einander in Android

Ich habe android:layout_marginTop="40dp" in der zweiten Karte verwendet, um die Lücke zwischen beiden Karten zu halten. Aber dann ist auch nur die erste Karte sichtbar.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 

    > 
    <!-- A CardView that contains a TextView --> 
<android.support.v7.widget.CardView 
xmlns:card_view="http://schemas.android.com/apk/res-auto" 
android:id="@+id/card_view" 
    android:layout_width="200dp" 
android:layout_height="200dp" 
card_view:cardCornerRadius="30dp" 
    android:foregroundGravity="center" 
    android:layout_gravity="center_vertical" 
    android:paddingTop="10dp" 
    android:layout_marginLeft="80dp" 
    android:layout_marginBottom="20dp" 

    > 
<TextView 
    android:id="@+id/info_text" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:hint="Encrypt Mode" 
    android:textSize="20dp" 
    android:textAllCaps="true" 
    android:gravity="center" 

    /> 
</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="200dp" 
     android:layout_height="200dp" 
     android:paddingTop="30dp" 
     card_view:cardCornerRadius="30dp" 
     android:foregroundGravity="center" 
     android:layout_gravity="center_vertical" 
     android:layout_marginLeft="80dp" 
     android:layout_marginTop="40dp" 

     > 
     <TextView 
      android:id="@+id/info_text2" 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:hint="Decrypt Mode" 
      android:textSize="20dp" 
      android:textAllCaps="true" 
      android:gravity="center" 

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

Wie beide Karten sichtbar machen?

+1

Welche Art von LinearLayout-Ausrichtung verwenden Sie? =) Vielleicht Problem in diesem? Versuche, android zu verwenden: orientation = "vertical" –

Antwort

1

geben Orientierung Attribut zu Ihrem Linearlayout

<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:layout_height="match_parent" 
    android:layout_width="match_parent" 
    android:orientation="vertical"> 
    <--child1 --> 
    <--child2 --> 
    </LinearLayout> 
1

oh, Linearlayout

als

<!-- A CardView that contains a TextView --> 
<android.support.v7.widget.CardView 
    xmlns:card_view="http://schemas.android.com/apk/res-auto" 
    android:id="@+id/card_view" 
    android:layout_width="200dp" 
    android:layout_height="200dp" 
    card_view:cardCornerRadius="30dp" 
    android:foregroundGravity="center" 
    android:layout_gravity="center_vertical" 
    android:paddingTop="10dp" 
    android:layout_marginLeft="80dp" 
    android:layout_marginBottom="20dp" 

    > 
    <TextView 
     android:id="@+id/info_text" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:hint="Encrypt Mode" 
     android:textSize="20dp" 
     android:textAllCaps="true" 
     android:gravity="center" 

     /> 
</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="200dp" 
    android:layout_height="200dp" 
    android:paddingTop="30dp" 
    card_view:cardCornerRadius="30dp" 
    android:foregroundGravity="center" 
    android:layout_gravity="center_vertical" 
    android:layout_marginLeft="80dp" 
    android:layout_marginTop="40dp" 

    > 
    <TextView 
     android:id="@+id/info_text2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:hint="Decrypt Mode" 
     android:textSize="20dp" 
     android:textAllCaps="true" 
     android:gravity="center" 

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

zur Wurzel hinzufügen 10