Android 如何将xml视图彼此对齐并从同一点开始
我在Android 如何将xml视图彼此对齐并从同一点开始,android,xml,Android,Xml,我在layout.xml中设计了红色标签,使其如图所示相互放置,但从同一起点“黑线”开始,我尝试了这一部分,但无法实现 请参阅下面的xml文件。 我试图将标有红色的每个视图的layout\u width更改为match\u parent,但这会使标签从最左边开始,就好像它们是左对齐的一样。请让我知道我应该添加什么到布局中,以使视图从黑线开始 xml: 输出图像: 有很多种方法可以解决这个问题 1,如果黑线是图像视图,则只需设置它的报告RealtiveLayout02布局。并将标签设置为ali
layout.xml
中设计了红色标签,使其如图所示相互放置,但从同一起点“黑线”开始,我尝试了这一部分,但无法实现
请参阅下面的xml文件。
我试图将标有红色的每个视图的layout\u width
更改为match\u parent
,但这会使标签从最左边开始,就好像它们是左对齐的一样。请让我知道我应该添加什么到布局中,以使视图从黑线开始
xml:
输出图像:
有很多种方法可以解决这个问题 1,如果黑线是
图像视图
,则只需设置它的报告RealtiveLayout02
布局。并将标签设置为alignedToParentLeft
2、黑线更可能不存在。因此只需将标签设置为alignedToParentLeft
,并将其margin\u left
设置为合适的数字即可
我想知道你是如何让“ImgTile”和“ImgPath”保持一个正确的位置的,就像他们一样 您在每个RelaviteLayout
中编写了android:layout_gravity=“center | center_vertical”
我建议您删除这行代码。此代码将自动居中
其子项<代码>垂直居中
正常。但Center
并不可取。相反,您也可以使用以下代码
android:layout_gravity="left|center_vertical"
使用下面的代码
尝试使用表布局。我很快就会尝试,并向informglad提供帮助。。。向上投票将是另一种乐趣:)
android:layout_gravity="left|center_vertical"
use below Code
<RelativeLayout
android:id="@+id/reportRealtiveLayout02"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<TextView
android:id="@+id/reportLocNameLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Name: "
android:layout_alignParentLeft="true"
android:textColor="@android:color/holo_red_dark"/>
<TextView
android:id="@+id/reportLocNameValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toRightOf="@+id/reportLocNameLabel"/>
<TextView
android:id="@+id/reportLocLatLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lat: "
android:textColor="@android:color/holo_red_dark"
android:layout_alignParentLeft="true"
android.layout_below="@+id/reportLocNameLabel"/>
<TextView
android:id="@+id/reportLocLatValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android.layout_below="@+id/reportLocNameValue"
android:layout_toRightOf="@+id/reportLocLatLabel"/>
<TextView
android:id="@+id/reportLocLngLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Lng: "
android:layout_alignParentLeft="true"
android.layout_below="@+id/reportLocNameLabel"
android:textColor="@android:color/holo_red_dark"/>
<TextView
android:id="@+id/reportLocLngValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android.layout_below="@+id/reportLocLatValue"
android:layout_toRightOf="@+id/reportLocLngLabel"/>
<TextView
android:id="@+id/reportTimeLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Time: "
android:layout_alignParentLeft="true"
android.layout_below="@+id/reportLocLngLabel"
android:textColor="@android:color/holo_red_dark"/>
<TextView
android:id="@+id/reportTimeValue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android.layout_below="@+id/reportLocLngValue"
android:layout_toRightOf="@+id/reportTimeLabel"/>
</RelativeLayout>