簡體   English   中英

在一行中顯示 2 個或更多文本視圖

[英]Display 2 or more textviews in one row

我看到了一些相同的問題,但我使用的是android:orientation="vertical"所以我不能使用方向作為水平。 如何在 1 行上顯示 2 個或更多文本視圖? (對不起我的英語水平)

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="vertical"
        android:background="@drawable/background"
        android:weightSum="1">
<TextView
        android:layout_width="62dp"
        android:layout_height="28dp"
        android:layout_gravity="right"
        android:text="Sign in"
        android:textColor="#7041EE"
        android:textSize="20dp" />

    <TextView
        android:id="@+id/nwah"
        android:layout_width="162dp"
        android:layout_height="28dp"
        android:layout_gravity="left"
        android:text="New around here?"
        android:textColor="#ACACAC"
        android:textSize="20dp" />


</LinearLayout>

在此處輸入圖片說明

<?xml version="1.0" encoding="utf-8"?>
    <LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        xmlns:tools="http://schemas.android.com/tools"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:context=".MainActivity"
        android:orientation="vertical"
        android:background="@drawable/background"
        android:weightSum="1">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="horizontal"
        android:weightSum="2">
    <TextView
        android:layout_width="0dp"
        android:layout_height="28dp"
        android:layout_gravity="right"
        android:layout_weight="1"
        android:text="Sign in"
        android:textColor="#7041EE"
        android:textSize="20dp" />

    <TextView
        android:id="@+id/nwah"
        android:layout_width="0dp"
        android:layout_height="28dp"
        android:layout_weight="1"
        android:layout_gravity="left"
        android:text="New around here?"
        android:textColor="#ACACAC"
        android:textSize="20dp" />
    </LinearLayout>
</LinearLayout>

您可以為 textView 添加另一個視圖

<LinearLayout // vertical
 <LinearLayout // hotizontal
  <TextView/>
  <TextView/>
 <LinearLayout/>
<LinearLayout/>

或者您可以使用約束布局

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM