Android:线性布局新线

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/10179258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-20 02:45:50  来源:igfitidea点击:

Android: Linear Layout new Line

android

提问by user1324936

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?

我使用 TextView 创建了如下所示的 LinearLayout。文本是可变的。如果元素变得比布局宽度大,它就会变得很糟糕。我想让文本流到一个新行,就像写书时那样。这可能吗?

<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
  1. 文本视图1文本编辑文本文本视图2
  2. textview2continuesin2ndrow

not like this:

不是这样的:

  1. textview1text edittext textview2text
  2. textview1cont
  1. textview1text edittext textview2text
  2. 文本视图1cont

采纳答案by Squonk

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>

回答by vara prasad

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

您可以android:orientation="vertical"在 linearlayout中使用以获取不同行中的元素

回答by Sushrut Kanetkar

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>