【发布时间】:2013-12-05 10:13:12
【问题描述】:
我在 android 中有一个活动,其中有一个编辑框和编辑框下方的 3 个按钮。请查看附件。启动此活动时,默认状态为 STATE1。(请参见图片)。默认情况下键盘是可见的。现在,当我按下后退按钮或释放键盘时,我希望调整编辑文本的大小并占据整个屏幕,如 STATE2 所示。
我不知道如何做到这一点。我将edittext的高度硬编码为基于目标设备的某个dp。我相信这必须改变。任何人都可以帮助我如何做到这一点。
布局文件的 XML 和屏幕截图如下
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#FFFFFF" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<EditText
android:id="@+id/EditMessage"
android:layout_width="fill_parent"
android:layout_height="150dp"
android:background="@drawable/newback"
android:gravity="top"
android:imeOptions="actionDone"
android:inputType="textMultiLine|textFilter|textVisiblePassword|textNoSuggestions"
android:maxLength="200"
android:padding="5dp"
android:textAppearance="?android:attr/textAppearanceMedium"
android:textColor="#000000"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="@+id/PostMessage"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:layout_marginRight="0.2dp"
android:background="@drawable/newbutton_corner"
android:text="@string/SubmitMessage"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<Button
android:id="@+id/CancelMessage"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:layout_marginRight="0.2dp"
android:background="@drawable/newbutton_corner"
android:text="@string/CancelMessage"
android:textColor="#FFFFFF"
android:textStyle="bold" />
<Button
android:id="@+id/DeleteMessage"
android:layout_width="0dp"
android:layout_height="45dp"
android:layout_weight="1"
android:background="@drawable/newbutton_corner"
android:text="@string/DeleteMessage"
android:textColor="#FFFFFF"
android:textStyle="bold" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
【问题讨论】:
标签: android android-layout android-activity android-edittext