在 cardview 中对齐项目
Aligning items in cardview
我希望我的名片如下所示
我保留了这样的布局
<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order# GAMH2103"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:gravity="start"
android:textSize="15dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirmed"
android:drawableRight="@drawable/check"
android:textColor="#00FF00"
android:gravity="end"
android:textSize="15dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginTop="5dp"
/>
</LinearLayout>
不知何故,我无法让 "confirmed" TextView 可见。不过我可以看到订单号。
我玩过 gravity
和 layout_gravity
但不知何故无法通过。
请帮忙。
谢谢,Lakshman。
一个简单的相对布局就可以完成这项工作。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order# GAMH2103"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:gravity="start"
android:textSize="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirmed"
android:drawableRight="@drawable/check"
android:textColor="#00FF00"
android:layout_gravity="end"
android:textSize="15dp"/>
</RelativeLayout>
注意gravity
和layout_gravity
的区别,如果在TextView
中使用gravity
,则属于[=21]中文字的位置=]invisible box 是 TextView
的边界,例如,另一方面,layout_gravity
属于视图在父级内部的位置。
使用以下 layout.This 将适合您。
始终首选使用相对布局而不是线性布局以获得更好的视图对齐。
<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order# GAMH2103"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:gravity="start"
android:textSize="15dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirmed"
android:textColor="#00FF00"
android:gravity="end"
android:textSize="15dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>
我希望我的名片如下所示
我保留了这样的布局
<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order# GAMH2103"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:gravity="start"
android:textSize="15dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirmed"
android:drawableRight="@drawable/check"
android:textColor="#00FF00"
android:gravity="end"
android:textSize="15dp"/>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="1dp"
android:background="@android:color/darker_gray"
android:layout_marginTop="5dp"
/>
</LinearLayout>
不知何故,我无法让 "confirmed" TextView 可见。不过我可以看到订单号。
我玩过 gravity
和 layout_gravity
但不知何故无法通过。
请帮忙。
谢谢,Lakshman。
一个简单的相对布局就可以完成这项工作。
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order# GAMH2103"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:gravity="start"
android:textSize="15dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Confirmed"
android:drawableRight="@drawable/check"
android:textColor="#00FF00"
android:layout_gravity="end"
android:textSize="15dp"/>
</RelativeLayout>
注意gravity
和layout_gravity
的区别,如果在TextView
中使用gravity
,则属于[=21]中文字的位置=]invisible box 是 TextView
的边界,例如,另一方面,layout_gravity
属于视图在父级内部的位置。
使用以下 layout.This 将适合您。
始终首选使用相对布局而不是线性布局以获得更好的视图对齐。
<android.support.v7.widget.CardView
android:layout_gravity="center"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
card_view:cardCornerRadius="2dp">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Order# GAMH2103"
android:layout_marginStart="5dp"
android:layout_marginLeft="5dp"
android:gravity="start"
android:textSize="15dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Confirmed"
android:textColor="#00FF00"
android:gravity="end"
android:textSize="15dp"/>
</RelativeLayout>
</android.support.v7.widget.CardView>