maxLines 和 inputType="textMultiLine" 不工作
maxLines and inputType="textMultiLine" not working
这是我的 EditText:
<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" />
EditText
的高度设置为 match_parent
。
父项的身高设置为wrap_content
,约束子项为ImageView
,其身高为wrap_content
。
因此,EditText
的高度受限于ImageView
的高度。
在您的 EditText
中使用 wrap_content
的高度,使其能够展开至完整尺寸。
这是我的 EditText:
<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" />
EditText
的高度设置为 match_parent
。
父项的身高设置为wrap_content
,约束子项为ImageView
,其身高为wrap_content
。
因此,EditText
的高度受限于ImageView
的高度。
在您的 EditText
中使用 wrap_content
的高度,使其能够展开至完整尺寸。