【发布时间】:2018-08-20 23:32:53
【问题描述】:
我试图将两个 TextView 并排放置,但不知何故我无法让它工作。我想要以下内容: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>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:gravity="right"
android:orientation="horizontal">
<Button
android:id="@+id/btn_update"
android:layout_width="45dp"
android:layout_height="35dp"
android:layout_marginRight="5dp"
android:layout_marginTop="100dp"
android:background="@drawable/edit"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
<Button
android:id="@+id/btn_delete"
android:layout_width="38dp"
android:layout_height="24dp"
android:layout_marginRight="5dp"
android:layout_marginTop="100dp"
android:background="@drawable/delete"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="" />
</LinearLayout>
</LinearLayout>
【问题讨论】:
-
如果你真的需要水平方向,为什么要给垂直方向?
-
只需将您的 LinearLayout 更改为方向 vertical 到 horizontal 你有 Textviews of addresses
-
我确实将方向设置为水平,但前两个文本视图很好。我有多个文本视图。第一行是地址:来自数据库的地址,第二行签入日期:从数据库签入日期,第三行签出日期:从数据库中提取的签出日期。
标签: java android android-layout android-linearlayout