Java 编辑文本视图未在新行上展开

Java 编辑文本视图未在新行上展开,java,android,android-layout,Java,Android,Android Layout,我正在尝试获取用户评论,按下enter按钮后,由于行更改,文本被隐藏。我 我正在尝试扩展我的EditText视图,以便至少显示4行注释 <LinearLayout android:id="@+id/comments_body_box" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_alignParentBottom="true" andro

我正在尝试获取用户评论,按下enter按钮后,由于行更改,文本被隐藏。我 我正在尝试扩展我的EditText视图,以便至少显示4行注释

<LinearLayout
    android:id="@+id/comments_body_box"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"
    android:layout_alignParentStart="true"
    android:background="#fff"
    android:elevation="8dp"
    android:gravity="right"
    android:maxHeight="150dp"
    android:orientation="horizontal"
    android:weightSum="10"
    app:layout_constraintBottom_toBottomOf="parent"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintStart_toStartOf="parent">

    <EditText
        android:id="@+id/comments_text_body"
        android:layout_width="151dp"
        android:layout_height="match_parent"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:layout_weight="8"
        android:inputType="textCapSentences|textMultiLine"
        android:maxHeight="100dp"
        android:maxLength="2000"
        android:maxLines="4"
        android:paddingBottom="12dp"
        android:paddingEnd="10dp"
        android:paddingLeft="10dp"
        android:paddingRight="10dp"
        android:paddingTop="16dp" />

    <ImageView
        android:id="@+id/comment_send"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:padding="12dp"
        app:srcCompat="@drawable/ic_send_black_24dp" />

</LinearLayout>

看起来您的
EditText
设置为
match\u parent

试着改变
android:layout\u height=“match\u parent”

android:layout\u height=“wrap\u content”
看起来您的
EditText
设置为
match\u parent

试着改变
android:layout\u height=“match\u parent”

android:layout\u height=“wrap\u content”

您需要将其添加到EditText属性中

  android:lines="4"
        <EditText
            android:id="@+id/comments_text_body"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:inputType="textCapSentences|textMultiLine"
            android:maxHeight="100dp"
            android:minLength="2000"
            android:minLines="4"
            android:scrollbars="vertical"
            android:paddingBottom="12dp"
            android:paddingEnd="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="16dp" />
另外,将“高度”设置为“包裹内容”

android:layout_height="wrap_content"

您需要将其添加到EditText属性中

  android:lines="4"
        <EditText
            android:id="@+id/comments_text_body"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="8"
            android:inputType="textCapSentences|textMultiLine"
            android:maxHeight="100dp"
            android:minLength="2000"
            android:minLines="4"
            android:scrollbars="vertical"
            android:paddingBottom="12dp"
            android:paddingEnd="10dp"
            android:paddingLeft="10dp"
            android:paddingRight="10dp"
            android:paddingTop="16dp" />
另外,将“高度”设置为“包裹内容”

android:layout_height="wrap_content"

首先我清理了你的代码

<LinearLayout
android:id="@+id/comments_body_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#fff"
android:elevation="8dp"
android:gravity="right"
android:maxHeight="150dp"
android:orientation="horizontal"
android:weightSum="10"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<EditText
    android:id="@+id/comments_text_body"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="8"
    android:inputType="textCapSentences|textMultiLine"
    android:maxHeight="100dp"
    android:maxLength="2000"
    android:maxLines="4"
    android:paddingBottom="12dp"
    android:paddingEnd="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="16dp" />

<ImageView
    android:id="@+id/comment_send"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:padding="12dp"
    app:srcCompat="@drawable/ic_send_black_24dp" />

1) 在线性布局中使用布局权重时,应使用布局宽度=“0dp”

2) 不要使用android:layout\u alignParentBottom=“true”和android:layout\u alignParentEnd=“true”,因为这在线性布局中没有意义


3) 使用layout_height=“wrap_content”是编辑文本,首先我清理了你的代码

<LinearLayout
android:id="@+id/comments_body_box"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentStart="true"
android:background="#fff"
android:elevation="8dp"
android:gravity="right"
android:maxHeight="150dp"
android:orientation="horizontal"
android:weightSum="10"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent">

<EditText
    android:id="@+id/comments_text_body"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="8"
    android:inputType="textCapSentences|textMultiLine"
    android:maxHeight="100dp"
    android:maxLength="2000"
    android:maxLines="4"
    android:paddingBottom="12dp"
    android:paddingEnd="10dp"
    android:paddingLeft="10dp"
    android:paddingRight="10dp"
    android:paddingTop="16dp" />

<ImageView
    android:id="@+id/comment_send"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:padding="12dp"
    app:srcCompat="@drawable/ic_send_black_24dp" />

1) 在线性布局中使用布局权重时,应使用布局宽度=“0dp”

2) 不要使用android:layout\u alignParentBottom=“true”和android:layout\u alignParentEnd=“true”,因为这在线性布局中没有意义


3) 使用layout_height=“wrap_content”作为编辑文本开始之前,您需要对代码进行一些更改

  • 如果使用的是
    android:layout\u weight
    属性,则应始终将宽度属性设置为
    android:layout\u width=“0dp”
  • 由于您使用的是LinearLayout,请删除属性
    android:layout\u alignParentBottom
    android:layout\u alignParentEnd
    。他们对这个案子无效
  • 由于您使用的是
    EditText
    下的
    ImageView
    ,因此最好为视图指定一个高度,而不是
    match\u parent
    ,或者在不需要固定大小的情况下使用
    wrap\u content
  • 您提到需要在
    EditText
    中显示至少4行文本。如果所有用例都需要这样做,请将属性
    android:minLines=“4”
    添加到您的
    EditText
    。如果您希望最多显示4行,那么您的代码
    android:maxLines=“4”
    工作正常

    为了防止文本随着行数的增加而隐藏,请将属性
    android:scrollbars=“vertical”
    添加到
    EditText

    您的最终编辑文本XML可能看起来像(假设至少需要4行。如果不需要,只需删除
    android:minLines
    属性)


    开始之前,您需要对代码进行一些更改

  • 如果使用的是
    android:layout\u weight
    属性,则应始终将宽度属性设置为
    android:layout\u width=“0dp”
  • 由于您使用的是LinearLayout,请删除属性
    android:layout\u alignParentBottom
    android:layout\u alignParentEnd
    。他们对这个案子无效
  • 由于您使用的是
    EditText
    下的
    ImageView
    ,因此最好为视图指定一个高度,而不是
    match\u parent
    ,或者在不需要固定大小的情况下使用
    wrap\u content
  • 您提到需要在
    EditText
    中显示至少4行文本。如果所有用例都需要这样做,请将属性
    android:minLines=“4”
    添加到您的
    EditText
    。如果您希望最多显示4行,那么您的代码
    android:maxLines=“4”
    工作正常

    为了防止文本随着行数的增加而隐藏,请将属性
    android:scrollbars=“vertical”
    添加到
    EditText

    您的最终编辑文本XML可能看起来像(假设至少需要4行。如果不需要,只需删除
    android:minLines
    属性)

    
    
    谢谢@Alexei,问题是整个布局都在swipeRefreshLayout中,这就是我添加所有额外属性的原因。layout_height=“wrap_content”修复了我的问题。谢谢@Alexei,问题是整个版面都在swipeRefreshLayout中,这就是我添加所有额外属性的原因。layout\u height=“wrap\u content”修复了我的问题。谢谢@john,这修复了我的问题:)谢谢@john,这修复了我的问题:)