使Android线性布局垂直扩展,因为我在里面输入编辑文本



我在屏幕底部的线性布局中有一个eddittext,有点像WhatsApp来写消息。我可以在编辑中添加新行,但线性布局保持不变,我希望线性布局在我输入更多行时扩展。我在线性布局上方有一个列表视图

这是我的布局 XML:

<RelativeLayout 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"
android:paddingTop="@dimen/activity_vertical_margin"
tools:context=".ChatActivity"
android:background="#ffffff">

<ListView
    android:id="@+id/listView"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_above="@+id/linlay"
    android:divider="@android:color/transparent"
    android:dividerHeight="0dp"/>


    <LinearLayout
        android:orientation="horizontal"
        android:id="linlay"
        android:layout_width="match_parent"
        android:layout_height="match_parent">
        <EditText
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/et_message"
            android:hint="Enter your message" />

我希望这个 Lin 布局随着编辑垂直扩展而扩展

    </LinearLayout>

<com.gc.materialdesign.views.ButtonFloat
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/btn_send"
    android:layout_alignTop="@+id/chatMessageView"
    android:layout_alignParentRight="true"
    android:layout_alignParentEnd="true"
    android:layout_marginRight="5dp"
    app:iconDrawable="@drawable/ic_action_send_now"
    android:background="@color/ChatBlue10" />

</RelativeLayout>

你可以使用minheight,

     <LinearLayout
        android:layout_alignParentBottom="true"
        android:id="@+id/layout_message"
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:clickable="true">
    <EditText
            android:id="@+id/textBody"
            android:layout_width="0dp"
            android:layout_weight="1"
            android:minHeight="48dp"
            android:hint="@string/send_text"
            android:maxLines="5"
            android:textSize="16sp"
            android:layout_height="wrap_content"/>
    <ImageView
         ....
         ....

否则,您能否向我们展示您的XML以解决更多您的问题

为了更好地回答您的问题,重要的是要知道您在布局中使用的所有元素是什么.xml。请把你所有的xml布局文件。

最新更新