Android多行消息编辑文本
我正在尝试制作一个小型聊天应用程序。现在我有了主活动布局,其中显示消息。一切正常,但我的编辑框只显示一行文本。我想让它像whatsapp一样,有多行 像这样: 以下是我的布局:Android多行消息编辑文本,android,android-layout,android-edittext,Android,Android Layout,Android Edittext,我正在尝试制作一个小型聊天应用程序。现在我有了主活动布局,其中显示消息。一切正常,但我的编辑框只显示一行文本。我想让它像whatsapp一样,有多行 像这样: 以下是我的布局: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" and
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/lstMessages"
android:transcriptMode="alwaysScroll"
android:layout_alignParentTop="true"
android:layout_above="@+id/editLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"/>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editLayout"
android:layout_alignParentBottom="true"
android:paddingTop="5dp"
android:paddingBottom="1dp"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<!---->
<EditText
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:id="@+id/messageField"
android:layout_toLeftOf="@+id/btnSend"
android:layout_alignParentTop="true"
android:layout_alignBottom="@+id/btnSend"
android:hint="@string/message_field_hint"
android:maxLines="3"
android:gravity="top"
android:inputType="textMultiLine"
android:imeOptions="actionSend"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnSend"
android:layout_alignParentRight="true"
android:paddingRight="10dp"
android:gravity="center"
android:text="@string/send_button_text"
android:textSize="14sp"/>
</RelativeLayout>
</RelativeLayout>
我不知道我该做什么。有人能帮我吗?试试这个:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".MainActivity">
<ListView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:id="@+id/lstMessages"
android:transcriptMode="alwaysScroll"
android:layout_alignParentTop="true"
android:layout_above="@+id/editLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"/>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="@+id/editLayout"
android:layout_alignParentBottom="true"
android:paddingTop="5dp"
android:paddingBottom="1dp"
android:paddingLeft="0dp"
android:paddingRight="0dp">
<!---->
<EditText
android:layout_width ="0dip"
android:layout_height ="wrap_content"
android:layout_weight ="1"
android:id="@+id/messageField"
android:inputType="textCapSentences|textMultiLine"
android:maxLines ="3"
android:maxLength ="2000"
android:hint="@string/message_field_hint"
android:imeOptions="actionSend"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="@+id/btnSend"
android:layout_alignParentRight="true"
android:paddingRight="10dp"
android:gravity="center"
android:text="@string/send_button_text"
android:textSize="14sp"/>
</LinearLayout>
</RelativeLayout>
你有没有试过让android:singleLine=“false”@Gleb测试我的答案?如果答案对你有帮助,你必须接受正确的答案,如果我的答案没有让我知道,我会更新它。@Skizo你的答案很接近,但不正确。事实上,我不记得出了什么问题,用RelativeLayout解决了这个问题。