卡片未正确对齐
Cards not getting aligned correctly
我正在尝试设置四张 cards.I 希望前两张卡片水平并排对齐,然后两张卡片需要在下方并水平对齐。
我正在使用两张单独的 LinearLayout
分别用于一行两张卡片(即每行两张卡片)。
问题是只有前两张牌可见,其他两张牌不可见。
XML code
<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>
您需要将 LinerLayout
的方向设置为 horizontal
,将 layout_height
的方向设置为 wrap_content
。
Like this below.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">
我正在尝试设置四张 cards.I 希望前两张卡片水平并排对齐,然后两张卡片需要在下方并水平对齐。
我正在使用两张单独的 LinearLayout
分别用于一行两张卡片(即每行两张卡片)。
问题是只有前两张牌可见,其他两张牌不可见。
XML code
<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>
您需要将 LinerLayout
的方向设置为 horizontal
,将 layout_height
的方向设置为 wrap_content
。
Like this below.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_marginTop="20dp">