简体   繁体   中英

How do you put two TextViews next to each other in a LinearLayout?

I am a beginner in Android Studios, and my TextViews will not be placed next to each other, instead one is on top of the other. I am really confused about what I did wrong.

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:orientation="horizontal" />

        <TextView
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="@string/already_registered"/>

        <TextView
            android:id="@+id/textview_login"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:paddingLeft="10dp"
            android:textStyle="bold"
            android:textColor="#ECAB71"
            android:textSize="16sp"
            android:text="@string/login"/>

</LinearLayout>

LinearLayout tag closed too early. Use > instead of /> in your LinearLayout element.

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp" android:orientation="horizontal">

    <TextView
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:text="Already registered"/>

    <TextView
            android:id="@+id/textview_login"
            android:layout_width="wrap_content"
            android:layout_height="35dp"
            android:paddingLeft="10dp"
            android:textStyle="bold"
            android:textColor="#ECAB71"
            android:textSize="16sp"
            android:text="login"/>

</LinearLayout>

You must clear the backslash in line 5

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:orientation="horizontal" >

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:text="@string/already_registered"/>

    <TextView
        android:id="@+id/textview_login"
        android:layout_width="wrap_content"
        android:layout_height="35dp"
        android:paddingLeft="10dp"
        android:textStyle="bold"
        android:textColor="#ECAB71"
        android:textSize="16sp"
        android:text="@string/login"/>

</LinearLayout>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM