卡片在 android 中相互叠加
Cards getting superimposed over one another in android
我正在尝试了解卡片 view.I 写了一个简单的代码来查看两个 cards.But 问题是第二张卡片不是 visible.I 认为第一张卡片与第二张卡,这就是第二张卡不可见的原因。
我在第二张卡片中使用了android:layout_marginTop="40dp"
来保持两者之间的差距cards.But,然后也只有第一张卡片可见。
<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>
如何让两张卡片都可见?
为您的线性布局提供方向属性
<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>
哦,添加android:orientation="vertical"
到根LinearLayout
作为
<!-- 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>
我正在尝试了解卡片 view.I 写了一个简单的代码来查看两个 cards.But 问题是第二张卡片不是 visible.I 认为第一张卡片与第二张卡,这就是第二张卡不可见的原因。
我在第二张卡片中使用了android:layout_marginTop="40dp"
来保持两者之间的差距cards.But,然后也只有第一张卡片可见。
<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>
如何让两张卡片都可见?
为您的线性布局提供方向属性
<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>
哦,添加android:orientation="vertical"
到根LinearLayout
作为
<!-- 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>