为了账号安全,请及时绑定邮箱和手机立即绑定

如何在 LinnearLayouts 中将两个彼此相邻的 TextViews 对齐?

如何在 LinnearLayouts 中将两个彼此相邻的 TextViews 对齐?

12345678_0001 2021-08-04 10:29:31
我试图将两个 TextViews 放在一起,但不知何故我无法让它工作。我想要以下内容:txtViewAddress: txtAddress 我试过把 android:layout_toRightOf="@id/txtViewAddress" 我也试过把 layout_toLeftOf,但两者都不起作用。希望大家能帮帮我。提前致谢。<?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" ><TextView    android:id="@+id/CalendarID"    android:layout_width="wrap_content"    android:layout_height="wrap_content"    android:text=""    android:textAppearance="?android:attr/textAppearanceMedium"    android:visibility="gone" /><LinearLayout    android:layout_width="match_parent"    android:layout_height="wrap_content"    android:orientation="horizontal">    <LinearLayout        android:layout_width="480dp"        android:layout_height="wrap_content"        android:orientation="vertical">        <TextView            android:id="@+id/txtViewAddress"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:text="Address: "            android:textAppearance="?android:attr/textAppearanceMedium"            android:textSize="22dp"            android:textStyle="bold"/>        <TextView            android:id="@+id/txtAddress"            android:layout_width="wrap_content"            android:layout_height="wrap_content"            android:layout_toEndOf="@id/txtViewAddress"            android:text="Hello"            android:textAppearance="?android:attr/textAppearanceMedium"            android:textSize="22dp"            android:textStyle="bold"/>    </LinearLayout>
查看完整描述

3 回答

?
MMMHUHU

TA贡献1834条经验 获得超8个赞

如果您需要在线性布局中并排放置视图,则布局的方向必须是水平的。

您还可以使用约束布局,它在将视图放置在屏幕上时具有更大的灵活性。


查看完整回答
反对 回复 2021-08-04
?
慕妹3146593

TA贡献1820条经验 获得超9个赞

<LinearLayout

    android:layout_width="480dp"

    android:layout_height="wrap_content"

    android:orientation="horizontal"

    android:weightSum="2">



    <TextView

        android:id="@+id/txtViewAddress"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:text="Address: "

        android:layout_weight="1"

        android:textAppearance="?android:attr/textAppearanceMedium"

        android:textSize="22dp"

        android:textStyle="bold"/>


    <TextView

        android:id="@+id/txtAddress"

        android:layout_width="wrap_content"

        android:layout_height="wrap_content"

        android:layout_toEndOf="@id/txtViewAddress"

        android:layout_weight="1"

        android:text="Hello"

        android:textAppearance="?android:attr/textAppearanceMedium"

        android:textSize="22dp"

        android:textStyle="bold"/>

</LinearLayout>

更改android:orientation="vertical"为android:orientation="horizontal"

,您也可以使用android:weightSum="2" weightSum 来定义视图的优先级,

如果您为线性布局中的所有视图赋予相同的权重,那么所有视图在线性布局中占据相同的空间


查看完整回答
反对 回复 2021-08-04
?
幕布斯6054654

TA贡献1876条经验 获得超7个赞

这应该如下


<LinearLayout

        android:layout_width="480dp"

        android:layout_height="wrap_content"

        android:orientation="horizontal">


.....

......

.....

    </LinearLayout>

而且我建议不要为布局提供固定宽度,而是将其设置为屏幕大小


查看完整回答
反对 回复 2021-08-04
  • 3 回答
  • 0 关注
  • 198 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信