【发布时间】:2018-07-13 11:11:33
【问题描述】:
假设我有一个简单的EditText 和一个按钮:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
tools:context=".DebugSimpleActivity">
<EditText
android:id="@+id/input"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginBottom="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginTop="?attr/actionBarSize"
android:ems="10"
android:gravity="start"
android:hint="Type here"
android:inputType="textMultiLine|textNoSuggestions"
android:singleLine="false" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal">
<Button
android:id="@+id/btnParse"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="parse"
app:layout_constraintTop_toBottomOf="@+id/input" />
</LinearLayout>
</LinearLayout>
这看起来像这样:
输入EditText 将扩展该可编辑文本字段,直到它最终不再适合屏幕,此时它将开始滚动。
关于这种行为,我想改变两点:
- 停止展开会导致按钮被推到屏幕外
- 不要逐渐扩大,立即跳到可能的最大尺寸
即我想要一个开始这么大的EditText
但是一旦您开始输入,就会尽可能地缩小以显示按钮。
有没有办法实现这种行为?
【问题讨论】:
-
尝试将
EditTextlayout_height更改为dp中的指定值,而不是wrap_content。 -
@Azhy 这会让我不得不根据运行应用程序的设备猜测正确的 dp 值。
-
这不是什么大问题,你可以使用
300dp这样的东西使用屏幕尺寸来适应它。
标签: android android-layout android-edittext