如何使一个按钮对齐布局中的权利? [英] How to make a Button align to the right in a layout?
本文介绍了如何使一个按钮对齐布局中的权利?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个具有在顶部一个TextView和底部一个TextView定制列表项的行。我想创建一个右对齐,而在垂直方向上居中的按钮。我怎样才能做到这一点XML?
<?XML版本=1.0编码=UTF-8&GT?;
< LinearLayout中的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =机器人:ATTR /列表preferredItemHeight
机器人:填充=6DIP> <的LinearLayout
机器人:方向=垂直
机器人:layout_width =0dip
机器人:layout_weight =1
机器人:layout_height =FILL_PARENT>
<的TextView
机器人:ID =@ + ID /的TopText
机器人:layout_width =FILL_PARENT
机器人:layout_height =0dip
机器人:layout_weight =1
机器人:重力=center_vertical
机器人:TEXTSIZE =18sp机器人:文字颜色=#FFFFFF/> <的TextView
机器人:layout_width =FILL_PARENT
机器人:layout_height =0dip
机器人:layout_weight =1
机器人:ID =@ + ID / bottomtext
机器人:单线=真
机器人:ellipsize =金字招牌
机器人:TEXTSIZE =15sp机器人:文字颜色=#FFFFFF/>< / LinearLayout中>
< / LinearLayout中>
解决方案
我的想法,他想是这样的:
<?XML版本=1.0编码=UTF-8&GT?;
<的RelativeLayout的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT机器人:layout_height =机器人:ATTR /列表preferredItemHeight
机器人:填充=6DIP>
<按钮的android:文本=@ + ID / Button01机器人:ID =@ + ID / Button01
机器人:layout_width =WRAP_CONTENT机器人:layout_alignParentRight =真
机器人:layout_centerVertical =真正的机器人:layout_height =WRAP_CONTENT/> <的LinearLayout机器人:方向=垂直
机器人:layout_toLeftOf =@ + ID / Button01的android:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT机器人:ID =@ + ID / TextLayout的>
< TextView的机器人:ID =@ + ID /的TopText的android:layout_width =FILL_PARENT
机器人:layout_height =0dip机器人:layout_weight =1
机器人:重力=center_vertical机器人:TEXTSIZE =18sp
机器人:文字颜色=#FFFFFF机器人:背景=#FFAABB/> <的TextView的android:layout_width =FILL_PARENT
机器人:layout_height =0dip机器人:layout_weight =1机器人:ID =@ + ID / bottomtext
机器人:单线=真正的机器人:ellipsize =金字招牌
机器人:TEXTSIZE =15sp机器人:文字颜色=#FFFFFF
机器人:背景=#FFBBAACC/>
< / LinearLayout中>
< / RelativeLayout的>
I have a custom ListItem row that has a TextView on the top and a TextView on the bottom. I would like to create a Button that is right aligned, and in centered vertically. How can I do this in XML?
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<LinearLayout
android:orientation="vertical"
android:layout_width="0dip"
android:layout_weight="1"
android:layout_height="fill_parent">
<TextView
android:id="@+id/toptext"
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:gravity="center_vertical"
android:textSize="18sp" android:textColor="#FFFFFF"/>
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight="1"
android:id="@+id/bottomtext"
android:singleLine="true"
android:ellipsize="marquee"
android:textSize="15sp" android:textColor="#FFFFFF"/>
</LinearLayout>
</LinearLayout>
解决方案
i was thinking he wanted something like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="?android:attr/listPreferredItemHeight"
android:padding="6dip">
<Button android:text="@+id/Button01" android:id="@+id/Button01"
android:layout_width="wrap_content" android:layout_alignParentRight="true"
android:layout_centerVertical="true" android:layout_height="wrap_content" />
<LinearLayout android:orientation="vertical"
android:layout_toLeftOf="@+id/Button01" android:layout_width="fill_parent"
android:layout_height="fill_parent" android:id="@+id/TextLayout">
<TextView android:id="@+id/toptext" android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="1"
android:gravity="center_vertical" android:textSize="18sp"
android:textColor="#FFFFFF" android:background="#FFAABB" />
<TextView android:layout_width="fill_parent"
android:layout_height="0dip" android:layout_weight="1" android:id="@+id/bottomtext"
android:singleLine="true" android:ellipsize="marquee"
android:textSize="15sp" android:textColor="#FFFFFF"
android:background="#FFBBAACC" />
</LinearLayout>
</RelativeLayout>
这篇关于如何使一个按钮对齐布局中的权利?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文