EditText强制提交按钮在屏幕上

时间:2015-01-05 01:01:11

标签: android android-layout android-edittext android-scrollview

我有一个表格供用户填写,表格的最后一项是支持多行的EditText。

<ScrollView 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=".ContactUs.ContactUs">

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical"
        android:paddingBottom="@dimen/baseline_margin_unit"
        android:paddingLeft="@dimen/baseline_margin_unit"
        android:paddingRight="@dimen/baseline_margin_unit">

        <LinearLayout
            android:id="@+id/contact_details"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="center_horizontal"
            android:orientation="vertical">

        </LinearLayout>

        <com.rengwuxian.materialedittext.MaterialEditText
            android:id="@+id/name"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/contact_us_name"
            android:inputType="textPersonName"
            app:floatingLabel="normal"
            app:floatingLabelText="@string/contact_us_name" />

        <com.rengwuxian.materialedittext.MaterialEditText
            android:id="@+id/phone"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/contact_us_phone_number"
            android:inputType="phone"
            app:floatingLabel="normal"
            app:floatingLabelText="@string/contact_us_phone_number" />

        <com.rengwuxian.materialedittext.MaterialEditText
            android:id="@+id/email"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/contact_us_email"
            android:inputType="textEmailAddress"
            app:floatingLabel="normal"
            app:floatingLabelText="@string/contact_us_email" />

        <com.rengwuxian.materialedittext.MaterialEditText
            android:id="@+id/message"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:hint="@string/contact_us_message"
            app:floatingLabel="normal"
            app:floatingLabelText="@string/contact_us_message" />

        <Button
            android:id="@+id/submit_email"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="right"
            android:text="@string/contact_us_send" />

    </LinearLayout>
</ScrollView>

当用户专注于EditText时,它会向上滚动视图以容纳屏幕键盘。我想要做的是强制自动滚动(在选择并添加新行)以始终保持提交按钮。

1 个答案:

答案 0 :(得分:0)

您是否看过https://developer.android.com/guide/topics/manifest/activity-element.html#wsoft

所以我的答案是将这些行添加到Android Manifest

<activity
    android:windowSoftInputMode="adjustResize">
</activity>