Search code examples
androidandroid-linearlayout

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>

Solution

  • 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>