Android 在屏幕底部将三个控件排成一行
如何指定一个布局,将三个控件放置在屏幕底部的一行中?我想要一个文本视图左对齐,两个按钮在一个组中居中。 如果没有“间隔”视图,所有三个控件将在左侧对齐。代码发布后,我就接近我想要的了。有没有办法用按钮将线性布局居中Android 在屏幕底部将三个控件排成一行,android,android-layout,Android,Android Layout,如何指定一个布局,将三个控件放置在屏幕底部的一行中?我想要一个文本视图左对齐,两个按钮在一个组中居中。 如果没有“间隔”视图,所有三个控件将在左侧对齐。代码发布后,我就接近我想要的了。有没有办法用按钮将线性布局居中 <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_width="fill_parent">
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_above="@+id/linearLayout1"
android:choiceMode="multipleChoice"
android:singleLine="true"
android:textStyle="bold" >
</ListView>
<!-- Row of buttons to control the display of the holdings -->
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal"
android:background="@color/btnarea"
>
<!-- setText here disables "selection" of items ???? -->
<TextView
android:id="@+id/selectedWPs"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:background="#ae6633"
android:text="Selected: "
android:layout_gravity="left"
android:layout_weight="0"
android:gravity="center"
android:textSize="20sp" />
<!-- spacer ???? why doesn't center_horizontal work??? -->
<View android:layout_width="200dp"
android:layout_height="match_parent"
android:background="@color/btnarea" />
<!-- how to center following ??? -->
<LinearLayout
android:id="@+id/buttonArea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_gravity="center_horizontal"
android:layout_weight="0"
>
<Button
android:id="@+id/quitBtn"
android:layout_width="match_parent"
android:layout_height="63dp"
android:background="#990000"
android:onClick="quitBtnClicked"
android:text="Quit"
android:textAlignment="center" />
<!-- spacer -->
<View
android:layout_width="40dp"
android:layout_height="40dp"
android:background="@color/btnarea" />
<Button
android:id="@+id/copyBtn"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight="0"
android:enabled="false"
android:background="#009900"
android:onClick="copyBtnClicked"
android:text="Copy"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
我尝试了下面给出的两种解决方案。我也没有做我想要的。
其中一个放置了三个控件:左中和右。另一个将最左边的控件扩展到整个屏幕,并将其他两个控件阻塞到右侧
第一个图像是我的尝试
试试这个
<?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="wrap_content"
android:orientation="vertical" >
<ListView
android:id="@android:id/list"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="@+id/linearLayout1"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:choiceMode="multipleChoice"
android:singleLine="true"
android:textStyle="bold" >
</ListView>
<!-- Row of buttons to control the display of the holdings -->
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#969696"
android:orientation="horizontal" >
<!-- setText here disables "selection" of items ???? -->
<TextView
android:id="@+id/selectedWPs"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.25"
android:background="#ae6633"
android:gravity="center"
android:text="Selected: "
android:textSize="20sp" />
<!-- spacer ???? why doesn't center_horizontal work??? -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.25"
android:background="#a3a3a3" />
<!-- how to center following ??? -->
<LinearLayout
android:id="@+id/buttonArea"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.5"
android:orientation="horizontal" >
<Button
android:id="@+id/quitBtn"
android:layout_width="0dp"
android:layout_height="63dp"
android:layout_weight="1"
android:background="#990000"
android:onClick="quitBtnClicked"
android:text="Quit"
android:textAlignment="center" />
<!-- spacer -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#d5d5d5" />
<Button
android:id="@+id/copyBtn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_weight="0"
android:background="#009900"
android:enabled="false"
android:onClick="copyBtnClicked"
android:text="Copy"
android:textAlignment="center" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
编辑:
<Button
android:id="@+id/copyBtn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#009900"
android:enabled="false"
android:onClick="copyBtnClicked"
android:text="Copy"
android:textAlignment="center" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#969696"
android:orientation="horizontal" >
<!-- setText here disables "selection" of items ???? -->
<TextView
android:id="@+id/selectedWPs"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.15"
android:background="#ae6633"
android:gravity="center"
android:text="Selected: "
android:textSize="20sp" />
<!-- spacer ???? why doesn't center_horizontal work??? -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.15"
android:background="#a3a3a3" />
<!-- how to center following ??? -->
<LinearLayout
android:id="@+id/buttonArea"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.70"
android:orientation="horizontal" >
<Button
android:id="@+id/quitBtn"
android:layout_width="0dp"
android:layout_height="63dp"
android:layout_weight="1"
android:background="#990000"
android:onClick="quitBtnClicked"
android:text="Quit"
android:textAlignment="center" />
<!-- spacer -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#d5d5d5" />
<Button
android:id="@+id/copyBtn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_weight="0"
android:background="#009900"
android:enabled="false"
android:onClick="copyBtnClicked"
android:text="Copy"
android:textAlignment="center" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#d5d5d5" />
</LinearLayout>
</LinearLayout>
编辑2:
<Button
android:id="@+id/copyBtn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#009900"
android:enabled="false"
android:onClick="copyBtnClicked"
android:text="Copy"
android:textAlignment="center" />
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#969696"
android:orientation="horizontal" >
<!-- setText here disables "selection" of items ???? -->
<TextView
android:id="@+id/selectedWPs"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_gravity="center"
android:layout_weight="0.15"
android:background="#ae6633"
android:gravity="center"
android:text="Selected: "
android:textSize="20sp" />
<!-- spacer ???? why doesn't center_horizontal work??? -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.15"
android:background="#a3a3a3" />
<!-- how to center following ??? -->
<LinearLayout
android:id="@+id/buttonArea"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="0.70"
android:orientation="horizontal" >
<Button
android:id="@+id/quitBtn"
android:layout_width="0dp"
android:layout_height="63dp"
android:layout_weight="1"
android:background="#990000"
android:onClick="quitBtnClicked"
android:text="Quit"
android:textAlignment="center" />
<!-- spacer -->
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#d5d5d5" />
<Button
android:id="@+id/copyBtn"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_weight="0"
android:background="#009900"
android:enabled="false"
android:onClick="copyBtnClicked"
android:text="Copy"
android:textAlignment="center" />
<View
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#d5d5d5" />
</LinearLayout>
</LinearLayout>
//尝试此布局并根据您的要求进行修改,如果有任何问题,请告诉我。。。
你能说说你改变了什么以及为什么要改变它吗?@NormR我改变了线性布局1
所有可见的东西。我没有设置特定的宽度,只是更改了要显示的权重。@NormR在该按钮中检查我的编辑hash two weight,因此只有我编辑了签出。我删除了weight=0行,并使用weight=1行进行测试。结果如上图所示。它没有做我要找的。@NormR从那张图片是你的要求。没有按要求做。见上图。