Axi*_*xus 3 height android multiline relativelayout android-edittext
因此布局非常简单.A ListView
占据屏幕的大部分,而RelativeLayout
底部包含EditText
a和a Button
.一切看起来都很棒,但问题是当用户键入并输入新行时,EditText
不会增加其高度,以便用户可以看到所有文本类型而无需滚动.你会认为WRAP_CONTENT
在它EditText
和它的父母RelativeLayout
都使用它会照顾它,但它不是出于某种原因.有任何想法吗?这是布局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>
Run Code Online (Sandbox Code Playgroud)
所以最后我无法理解.相反,我使用了一个LinearLayout
而不是RelativeLayout
嵌套的布局.这是新的布局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" >
<LinearLayout
android:id="@+id/postCommentLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:orientation="horizontal"
android:visibility="visible" >
<EditText
android:id="@+id/viewCommentsInsertCommentTextEdit"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:ems="10"
android:hint="@string/enter_comment"
android:inputType="textCapSentences|textMultiLine" />
<Button
android:id="@+id/viewCommentsPostCommentButton"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_gravity="bottom"
android:layout_weight="4"
android:text="@string/post" />
</LinearLayout>
<ListView
android:id="@+id/entriesListView"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="@id/postCommentLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:focusable="false" >
</ListView>
</RelativeLayout>
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
3605 次 |
最近记录: |