Android Studio 上的 LinearLayout 对齐
Alignment in LinearLayout on Android Studio
我是 Android Studio 的新手,现在我被对齐困住了。我环顾四周并进行了搜索,但我找到的解决方案并没有解决我的问题或带来了另一个问题。
我的布局是这样的:
view image
海拔:
10.0
纬度:
纬度测试
经度:
经度测试:
我需要在左边放置 Altitude、Latitude 和 Longitude,在右边放置 10.0、latitudeTest 和 longitudeTeste,有点像这样:
海拔: 10.0
纬度: latitudeTest
经度: longitudeTest
这是我的代码
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/item_horizontal_margin"
android:layout_marginEnd="@dimen/item_horizontal_margin"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Altitude:-->
android:text="@string/lb_altitude" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--10.0:-->
android:text="@={``+waypoint.altitude}" />
<TextView
android:id="@+id/lb_latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Latitude:-->
android:text="@string/lb_latitude" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lb_latitude"
android:text="latitudeTest" />
<TextView
android:id="@+id/lb_longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Longitude:-->
android:text="@string/lb_longitude" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lb_longitude"
android:text="longitudeTeste" />
</LinearLayout>
感谢任何帮助!
LinearLayout "一种将其他视图水平排列在单列中或垂直排列在单行中的布局。"来自 here
在 LinearLayout 中你只有一列。如果您希望多个元素在两个方向上彼此相邻,请使用另一种布局。
以下应该有效。您需要将 TextView 放置在不同的布局中以安排它们的位置。你会习惯的,一开始它很复杂。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/item_horizontal_margin"
android:layout_marginEnd="@dimen/item_horizontal_margin"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Altitude:-->
android:text="@string/lb_altitude" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--10.0:-->
android:text="@={``+waypoint.altitude}" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/lb_latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Latitude:-->
android:text="@string/lb_latitude" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lb_latitude"
android:text="latitudeTest" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/lb_longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Longitude:-->
android:text="@string/lb_longitude" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lb_longitude"
android:text="longitudeTeste" />
</LinearLayout>
</LinearLayout>
我是 Android Studio 的新手,现在我被对齐困住了。我环顾四周并进行了搜索,但我找到的解决方案并没有解决我的问题或带来了另一个问题。
我的布局是这样的:
view image
海拔:
10.0
纬度:
纬度测试
经度:
经度测试:
我需要在左边放置 Altitude、Latitude 和 Longitude,在右边放置 10.0、latitudeTest 和 longitudeTeste,有点像这样:
海拔: 10.0
纬度: latitudeTest
经度: longitudeTest
这是我的代码
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/item_horizontal_margin"
android:layout_marginEnd="@dimen/item_horizontal_margin"
android:orientation="vertical">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Altitude:-->
android:text="@string/lb_altitude" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--10.0:-->
android:text="@={``+waypoint.altitude}" />
<TextView
android:id="@+id/lb_latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Latitude:-->
android:text="@string/lb_latitude" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lb_latitude"
android:text="latitudeTest" />
<TextView
android:id="@+id/lb_longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Longitude:-->
android:text="@string/lb_longitude" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lb_longitude"
android:text="longitudeTeste" />
</LinearLayout>
感谢任何帮助!
LinearLayout "一种将其他视图水平排列在单列中或垂直排列在单行中的布局。"来自 here
在 LinearLayout 中你只有一列。如果您希望多个元素在两个方向上彼此相邻,请使用另一种布局。
以下应该有效。您需要将 TextView 放置在不同的布局中以安排它们的位置。你会习惯的,一开始它很复杂。
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="@dimen/item_horizontal_margin"
android:layout_marginEnd="@dimen/item_horizontal_margin"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Altitude:-->
android:text="@string/lb_altitude" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--10.0:-->
android:text="@={``+waypoint.altitude}" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/lb_latitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Latitude:-->
android:text="@string/lb_latitude" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lb_latitude"
android:text="latitudeTest" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/lb_longitude"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
<!--Longitude:-->
android:text="@string/lb_longitude" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@id/lb_longitude"
android:text="longitudeTeste" />
</LinearLayout>
</LinearLayout>