Android 安卓如何在其他小部件保持左对齐的同时右对齐按钮
我是Android新手,我的应用程序终于可以运行了,但是我的布局有问题 下面的Android 安卓如何在其他小部件保持左对齐的同时右对齐按钮,android,xml,android-layout,justify,Android,Xml,Android Layout,Justify,我是Android新手,我的应用程序终于可以运行了,但是我的布局有问题 下面的xml已被剥离,但在我标记它的位置,我有4个水平布局 每个都有不同的小部件微调器,SeekBar和单选按钮,都用分隔符分隔 每次选择一个设置,然后按右侧的Set按钮 我的问题是,尽管所有小部件都整齐地左对齐,但按钮的垂直对齐到处都是 如果我只玩widget,它将不适合不同的安卓设备 我如何使按钮垂直排列到右侧,而不从左侧移动所有其他按钮 GETTING
xml
已被剥离,但在我标记它的
位置,我有4个水平布局
每个都有不同的小部件微调器
,SeekBar
和单选按钮
,都用分隔符分隔
每次选择一个设置,然后按右侧的Set
按钮
我的问题是,尽管所有小部件都整齐地左对齐,但按钮的垂直对齐到处都是
如果我只玩widget,它将不适合不同的安卓设备
我如何使按钮
垂直排列到右侧,而不从左侧移动所有其他按钮
GETTING WANT
------------------------------- --------------------------------
| <Spinner> <button> | | <Spinner> <button> |
| < -------- Divider --------> | | < -------- Divider --------> |
| <RadioButton > <button> | | <RadioButton> <button> |
| < -------- Divider --------> | | < -------- Divider --------> |
| <SeekBar> <button> | | <SeekBar> <button> |
| < -------- Divider --------> | | < -------- Divider --------> |
| <RadioButton> <button> | | <RadioButton> <button> |
------------------------------- --------------------------------
得到想要的东西
------------------------------- --------------------------------
| | | |
|<-----------分隔器----------------->| |<-----------分隔器---------------->|
| | | |
|<-----------分隔器----------------->| |<-----------分隔器---------------->|
| | | |
|<-----------分隔器----------------->| |<-----------分隔器---------------->|
| | | |
------------------------------- --------------------------------
这是我的相关代码:
content_main.xml
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
tools:scrollY="?android:attr/scrollbarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<repeats> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Spinner
android:id="@+id/dynamic_TZ_spinner"
android:layout_width="223dp"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/dp20"
android:layout_marginRight="@dimen/dp20" />
<Button
android:id="@+id/TZ_btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/set" />
</LinearLayout>
<View
android:id="@+id/divider3"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_marginTop="@dimen/dp10"
android:background="?android:attr/listDivider"
android:visibility="visible" />
....
</LinearLayout>
</RelativeLayout>
</android.support.constraint.ConstraintLayout>
content\u main.xml
....
您可以为每个小部件和按钮使用线性布局(Column)尝试以下方法:-
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
tools:context=".MainActivity"
tools:showIn="@layout/activity_main">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_vertical"
tools:scrollY="?android:attr/scrollbarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<repeats> <RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Spinner
android:id="@+id/dynamic_TZ_spinner"
android:layout_width="223dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_marginLeft="@dimen/dp20"
android:layout_marginRight="@dimen/dp20" />
<Button
android:id="@+id/TZ_btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="@string/set" />
</RelativeLayout>
<View
android:id="@+id/divider3"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_marginTop="@dimen/dp10"
android:background="?android:attr/listDivider"
android:visibility="visible" />
....
</LinearLayout>
</RelativeLayout>
....
您可以使用子对象中的框架布局
和布局
属性来实现
对于一行使用:
<FrameLayout
android:padding="8dp"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<RadioButton
android:id="@+id/radioBtn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="start|center_vertical"
android:text="Radio Button" />
<Button
android:id="@+id/btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="end|center_vertical"
android:text="Button" />
</FrameLayout>
请尝试这种方式,并注意当您想将小部件放在其父部件的右侧或左侧时,请使用“android:layout\u alignParentRight=“true”或“android:layout\u alignParentLeft=“true”
....
感谢您将直系亲属改为亲属
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
xmlns:tools="http://schemas.android.com/tools"
android:gravity="center_vertical"
tools:scrollY="?android:attr/scrollbarSize">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Spinner
android:id="@+id/dynamic_TZ_spinner"
android:layout_width="223dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_margin="@dimen/dp20" />
<Button
android:id="@+id/TZ_btnSubmit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_margin="@dimen/dp20"
android:text="@string/set" />
</RelativeLayout>
<View
android:id="@+id/divider3"
android:layout_width="match_parent"
android:layout_height="5dp"
android:layout_marginTop="10dp"
android:background="?android:attr/listDivider"
android:visibility="visible" />
....
</LinearLayout>
</RelativeLayout>