a874 a874 - 4 months ago 10
Android Question

Cards getting superimposed over one another in android

I am trying to learn about card view.I wrote a simple code to view two cards.But the problem is that the second card is not visible.I think that first card is coinciding with the second card,that's why second card is not visible.

I have used

android:layout_marginTop="40dp"
in the second card to maintain the gap between both cards.But,then also only first card is visible.

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




How to make both cards visible ?

Answer

provide orientation attribute to your 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>
Comments