【发布时间】:2015-07-14 10:36:09
【问题描述】:
这是我的编辑文本:
<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:maxLines="4"
android:layout_weight="15" />
我希望它将输入行数扩展到最多 4 行(因此,maxLines="4")。但是,它仍然显示 1 行(实际上 1 和第二行的四分之一是可见的)。
我尝试添加android:lines="4" 和"android:singleLine="false",但无济于事。如何让它工作?
这是完整的xml文件:
<RelativeLayout
android:background="@color/colorBackground"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/app_bar"
layout="@layout/app_bar" />
<RelativeLayout
android:layout_below="@+id/app_bar"
android:id="@+id/rlRest"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:paddingBottom="7dp"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
tools:context=".MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/llInput">
<ListView
android:id="@+id/lvMessages"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:id="@+id/llInput"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal">
<EditText
android:id="@+id/etMessage"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:inputType="textMultiLine"
android:maxLines="4"
android:layout_weight="15"/>
<ImageButton
android:id="@+id/bSend"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="@mipmap/ic_send" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
<fragment
android:id="@+id/fragmentUsers"
android:name="com.example.abc.OnlineNavDrawerFragment"
android:layout_width="250dp"
android:layout_height="match_parent"
android:layout_gravity="start"
app:layout="@layout/fragment_online_nav_drawer"
tools:layout="@layout/fragment_online_nav_drawer" />
【问题讨论】:
-
从您的编辑文本中删除 layout_weight 属性。
-
为什么会有问题?我的布局确实需要它。
-
我建议你使用相对布局而不是线性布局。使用 relativelayout 可为您提供更好的布局自定义。您还可以通过避免嵌套布局来提高性能。
-
@Sree14 做到了。还是不行。
-
edittext 的高度为 match_parent。父级是wrap_content,约束子级是imageview,它的高度是wrap_content。因此,edittext 的高度就是 imageview 的高度。在您的编辑文本中使用 wrap_content。
标签: android xml android-edittext