[英]Android LinearLayout button alignment
我想將“取消並保存”按鈕center
對齊。 但是下面的代碼將按鈕對齊到center_vertical
,但是按鈕沒有水平居中對齊。 而是它們向左對齊。 如何在水平和垂直方向上將這些按鈕對准中心?
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="14sp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="14sp" />
</LinearLayout>
嘗試這個
<LinearLayout
android:id="@+id/llCardButtom"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<com.ecw.healow.mom.widget.TypefaceTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:gravity="center"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="14sp"
obs:typefaceVariant="titillium_web_regular" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/mom_card_button_vert_line"
android:contentDescription="@string/divider" />
<com.ecw.healow.mom.widget.TypefaceTextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/save"
android:gravity="center"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="14sp"
obs:typefaceVariant="titillium_web_regular" />
</LinearLayout>
我認為您必須使用layout_weight屬性來進行這種設計。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="@string/cancel"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="14sp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:gravity="center"
android:layout_weight="1"
android:textColor="#000000"
android:textSize="14sp"/>
</LinearLayout>
我認為您的意思是使用屬性:
android:layout_gravity="center"
在線性布局上而不是在單個內容上。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.