Android 如何在右侧设置RelativeLayout父级
嗨,我是android的新手,在这里我在Android 如何在右侧设置RelativeLayout父级,android,android-layout,Android,Android Layout,嗨,我是android的新手,在这里我在LinearLayout上创建了两个RelativeLayout 我的要求是我想在右侧设置第二个相对布局 根据我的代码,屏幕看起来像我的下图 那么,如何在父级右侧设置secondRelativeLayout 代码: 试试这个布局。我已对您的布局进行了一些更改。我已经删除了childLinear Layout,因为它没有用,或者android:Layout\u alignParentRight=“true”不会受到影响。还添加了相对布局作为根布局
LinearLayout上创建了两个RelativeLayout
我的要求是我想在右侧设置第二个相对布局
根据我的代码,屏幕看起来像我的下图
那么,如何在父级右侧设置secondRelativeLayout
代码:
试试这个布局
。我已对您的布局进行了一些更改。我已经删除了childLinear Layout
,因为它没有用,或者android:Layout\u alignParentRight=“true”
不会受到影响。还添加了相对布局作为根布局
试试这个布局
。我已对您的布局进行了一些更改。我已经删除了childLinear Layout
,因为它没有用,或者android:Layout\u alignParentRight=“true”
不会受到影响。还添加了相对布局作为根布局
在两个相对视图之间插入第三个视图
:
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
由于它的布局重量,这将“推”第二个相对视图到右侧。在两个相对视图之间插入第三个视图
:
<View
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_weight="1" />
由于它的布局权重,这将“推”第二个相对布局到右侧。线性布局没有要设置的此类属性:
因此,您必须添加带有权重的视图,以覆盖中间的空白区域
线性布局没有要设置的此类属性:
因此,您必须添加带有权重的视图,以覆盖中间的空白区域
要使用android:layout\u alignParentRight=“true”,父级应该是RelativeLayout。你亲戚的父母是直线型的,如果我没弄错的话,你希望亲戚在父母的右边。要么将父对象设置为RelativeLayout,要么将权重总和指定给LinearLayout,并将权重指定给子对象。为了使用android:layout\u alignParentRight=“true”,父对象应为RelativeLayout。你亲戚的父母是直线型的,如果我没弄错的话,你希望亲戚在父母的右边。要么让家长相对化,要么给孩子线性布局和权重加和。在第二个相对化中尝试
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="0dp"
android:background="@android:color/holo_red_light">
android:layout\u alignParentRight
属性仅适用于RelativeLayout
的子级。现在,您正在线性布局的子级中使用它,因此它将不起作用。请在第二个RelativeLayout
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="0dp"
android:background="@android:color/holo_red_light">
android:layout\u alignParentRight
属性仅适用于RelativeLayout
的子级。现在,您正在线性布局的子级中使用它,因此它将不起作用。您几乎没有办法完成所需的工作。我给你2英镑
- 首先,您可以将“父布局”更改为相对布局,并为这两个布局添加alignParentRight=“true”和alignParentLeft=“true”
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="right"
android:layout_marginRight="0dp"
android:background="@android:color/holo_red_light">
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="2"
android:padding="5dp">
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="@android:color/holo_blue_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ItemCode"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="GG00929-023"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Price"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="176000"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<RelativeLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_marginRight="0dp"
android:background="@android:color/holo_red_light">
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="On Hand"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Reserve"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.68"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cut Qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="0.00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Balance"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text=":"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="5dp"
android:text="372.89"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
</LinearLayout>
</LinearLayout>