Android LinearLayout按钮对齐
我想将取消和保存按钮对齐到Android LinearLayout按钮对齐,android,android-layout,Android,Android Layout,我想将取消和保存按钮对齐到中心。但是下面的代码将按钮对齐到垂直居中,但是按钮没有水平居中对齐。相反,它们是左对齐的。如何将这些按钮水平和垂直对齐到中心 <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_alignParentBottom="true" android:orie
中心
。但是下面的代码将按钮对齐到垂直居中
,但是按钮没有水平居中对齐。相反,它们是左对齐的。如何将这些按钮水平和垂直对齐到中心
<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>
我想你的意思是使用属性:
android:layout_gravity="center"
在线性布局上,而不是在单个内容上。试试这个
<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>
我认为您必须使用布局权重属性来进行此类设计
<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>
在您的布局中我看不到任何按钮?您可以发布整个XML文件吗?按钮小部件声明在哪里?将android:gravity=“center”
应用于您的线性布局
。com.ecw.healow.mom.widget.TypefaceTextView是按钮。:)TypefaceTextView
是您的自定义按钮吗??另外,您正在使用android:layout\u weight=“1”
属性,因此需要应用宽度0dp
,而不是wrap\u内容。