我正在尝试通过RelativeLayout
向用户显示信息,但当我使用layout_marginTop
或paddingTop
在我的项目之间创建一些间距时,下面的项目赢了“考虑到它们将开始重叠。
以下是一些有助于了解我的问题的照片:
初步情况:
向android:marginTop="48dip"
添加TextView
以更好地说明问题:
我也尝试将相同的android:marginTop="48dip"
添加到EditText
,但结果也出乎意料。 (链接到屏幕截图可以在评论中找到,因为信誉低于10的用户不能发布超过2个链接)
我正在使用的布局(简化版)
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingLeft="16dp"
android:paddingRight="16dp"
android:paddingTop="8dp">
<!--Identification part-->
<TextView
android:id="@+id/idPartTV"
android:text="Site"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true" />
<View
android:id="@+id/idPartLine"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="@id/idPartTV"
android:layout_marginTop="4dip"
android:background="@android:color/darker_gray" />
<!--Site name-->
<TextView
android:id="@+id/siteNameTV"
android:text="Name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/idPartLine"
android:layout_marginTop="8dip" />
<EditText
android:id="@+id/siteName"
local:MvxBind="Text Name"
android:layout_below="@id/idPartLine"
android:layout_toRightOf="@+id/transTV"
android:layout_alignBaseline="@id/siteNameTV"
android:layout_width="wrap_content"
android:layout_height="48dip" />
<!--Site ID-->
<TextView
android:id="@+id/siteIdTV"
android:text="ID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/siteName" />
<EditText
android:id="@+id/siteID"
local:MvxBind="Text Id"
android:layout_width="wrap_content"
android:layout_height="48dip"
android:layout_below="@id/siteName"
android:layout_toRightOf="@id/transTV"
android:layout_alignBaseline="@id/siteIdTV" />
<!--location Part-->
<TextView
android:id="@+id/locPartTV"
android:text="Location"
android:textColor="#FFFFFF"
android:textSize="20sp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/siteID" />
<View
android:id="@+id/locPartLine"
android:layout_width="wrap_content"
android:layout_height="1dp"
android:layout_below="@id/locPartTV"
android:background="@android:color/darker_gray"
android:layout_marginTop="4dip" />
<!--Latitude-->
<TextView
android:id="@+id/latTV"
android:text="Latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/locPartLine" />
<EditText
android:id="@+id/latitude"
local:MvxBind="Text Latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/locPartLine"
android:layout_toRightOf="@id/transTV"
android:layout_alignBaseline="@id/latTV"
android:inputType="numberDecimal" />
<!--Longitude-->
<TextView
android:id="@+id/longTV"
android:text="Longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/latitude" />
<EditText
android:id="@+id/longitude"
local:MvxBind="Text Longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="@id/latitude"
android:layout_toRightOf="@id/transTV"
android:layout_alignBaseline="@id/longTV"
android:inputType="numberDecimal" />
</RelativeLayout>
</ScrollView>
在上面的代码片段中, transTV 是我最大的TextView
。我正在使用它来确保所有EditText
都垂直对齐。 SiteID 是另一个EditText
,位于此处显示的位置之上。因为我有很多这些,所以我删除了我的代码以避免冗余。
在我对android:marginTop
和RelativeLayout
的想法中,应该考虑在纬度和分离线之间添加一些空格来计算经度的位置,因为它被设置为低于纬度使用android:layout_below
。