Android: Linear Layout new Line

后端 未结 3 1479
佛祖请我去吃肉
佛祖请我去吃肉 2021-01-01 13:27

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 n

相关标签:
3条回答
  • 2021-01-01 14:02

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

    0 讨论(0)
  • 2021-01-01 14:16

    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>
    
    0 讨论(0)
  • 2021-01-01 14:22

    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>
    
    0 讨论(0)
提交回复
热议问题