因此,布局相当简单。一个占据大部分屏幕的ListView,以及底部包含EditText和右侧Button的RelativeLayout。一切看起来很棒,但问题是,随着用户输入新行,EditText不会增加其高度,以便用户可以看到所有文本而无需滚动。您可能会认为在EditText及其父RelativeLayout上使用WRAP_CONTENT就可以解决这个问题,但由于某种原因它并不能。有任何想法吗?下面是Layout XML:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:id="@+id/postCommentRelativeLayout"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:visibility="visible" >
<Button
android:id="@+id/viewCommentsPostCommentButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="false"
android:text="@string/post" />
<EditText
android:id="@+id/viewCommentsInsertCommentTextEdit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@id/viewCommentsPostCommentButton"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="false"
android:layout_toLeftOf="@+id/viewCommentsPostCommentButton"
android:ems="10"
android:hint="@string/enter_comment"
android:inputType="textCapSentences|textMultiLine" >
<requestFocus />
</EditText>
</RelativeLayout>
<ListView
android:id="@+id/entriesListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/postCommentRelativeLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:focusable="false" >
</ListView>
</RelativeLayout>