Android: Linear Layout new Line-ThrowExceptions

Exception or error:

I created a LinearLayout like below with TextView. The Text is variable. If the Elements gets bigger than the Layout width it gets nasty. I want to have the text flow to a new line just one would do when writing a book. Is this possible?

<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content" >

<TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="xx"
            android:textAppearance="?android:attr/textAppearanceSmall" />

<EditText ...>

<TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="xx"
            android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>

edit

like this:

  1. textview1text edittext textview2
  2. textview2continuesin2ndrow

not like this:

  1. textview1text edittext textview2text
  2. textview1cont
How to solve:

Try something like…

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent" >
        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="xx"
            android:textAppearance="?android:attr/textAppearanceSmall" />
        <EditText ...>
    </LinearLayout>
    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="fill_parent"
            android:text="xx"
            android:textAppearance="?android:attr/textAppearanceSmall" />
    </LinearLayout>
</LinearLayout>

###

you can use android:orientation="vertical" within linearlayout to get elements in different lines

###

Try Something like this

<?xml version="1.0" encoding="utf-8"?>
<android.widget.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"
    android:orientation="vertical"
    tools:context="com.example.sushrut.recipedemo.MainActivity">

    <android.widget.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="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginBottom="40dp"
        android:layout_marginTop="40dp"
        android:orientation="horizontal"
        tools:context="com.example.sushrut.recipedemo.MainActivity">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/cameraActionButton"
            android:layout_width="68dp"
            android:layout_height="68dp"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"

            app:fabSize="normal"
            app:srcCompat="@android:drawable/ic_menu_camera" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/choiceActionBtn"
            android:layout_width="68dp"
            android:layout_height="68dp"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"

            app:fabSize="normal"
            app:srcCompat="@android:drawable/ic_input_add" />

    </android.widget.LinearLayout>

    <android.widget.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="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:orientation="horizontal"
        tools:context="com.example.sushrut.recipedemo.MainActivity">

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/addToLibraryBtn"
            android:layout_width="68dp"
            android:layout_height="68dp"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:clickable="true"
            app:fabSize="normal"
            app:srcCompat="@android:drawable/ic_menu_save" />

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/recipeBrowseBtn"
            android:layout_width="68dp"
            android:layout_height="68dp"
            android:layout_gravity="center"
            android:layout_marginBottom="20dp"
            android:layout_marginLeft="20dp"
            android:layout_marginRight="20dp"
            android:layout_marginTop="20dp"
            android:clickable="true"
            app:fabSize="normal"
            app:srcCompat="@android:drawable/btn_plus" />
    </android.widget.LinearLayout>

</android.widget.LinearLayout>

Leave a Reply

Your email address will not be published. Required fields are marked *