Android:键盘隐藏

时间:2015-07-11 18:21:54

标签: android android-layout android-xml android-softkeyboard android-scrollview

我有一个详细视图,其中编辑了项目的属性。这些可以是姓名,地址等。当屏幕进入时,键盘会自动显示到第一个TextInputLayout(参见第一张图片)。

但是当我用电话按钮隐藏键盘时,空间仍然是空的(见第二张图片)。但为什么?它应该看起来像第三张图片。

布局基本上如图4所示。三个图像应位于屏幕的底部,而上面的内容应该是可滚动的。如第三张图所示,无论如何,对齐都是错误的!?

键盘显示: keyboard shown

键盘隐藏 - 它背后的元素消失了! keyboard hidden

隐藏键盘 - 正确布局。 correct layout

XML中定义的布局。 layout

<LinearLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:padding="16dp">

    <ScrollView
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

    <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="vertical">

            <TableLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal"
                    android:stretchColumns="0"
                    >

                <TableRow android:layout_marginBottom="16dp">
                    <android.support.design.widget.TextInputLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical">
                        <EditText
                                android:id="@+id/edit_nick_name"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical"
                                android:hint="your nickname"
                                android:textSize="24sp"
                                android:fontFamily="sans-serif-thin"
                                />
                    </android.support.design.widget.TextInputLayout>

                    <ImageButton
                            android:id="@+id/btn_scan_name"
                            android:src="@mipmap/ic_camera_alt_white_24dp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:hint="@string/action_scan"
                            android:fontFamily="sans-serif-thin"
                            android:layout_gravity="center_vertical"
                            />
                </TableRow>

                <TableRow android:layout_marginBottom="16dp">
                    <android.support.design.widget.TextInputLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical">
                        <EditText
                                android:id="@+id/edit_location"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical"
                                android:hint="your address"
                                android:textSize="24sp"
                                android:fontFamily="sans-serif-thin"
                                />
                    </android.support.design.widget.TextInputLayout>

                    <ImageButton
                            android:id="@+id/btn_car_set_location_by_gps"
                            android:src="@mipmap/ic_my_location_white_24dp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:hint="@string/action_scan"
                            android:fontFamily="sans-serif-thin"
                            android:layout_gravity="center_vertical"
                            />
                </TableRow>

                <TableRow android:layout_marginBottom="16dp">
                    <android.support.design.widget.TextInputLayout
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:layout_gravity="center_vertical">
                        <EditText
                                android:id="@+id/edit_end_time"
                                android:layout_width="match_parent"
                                android:layout_height="wrap_content"
                                android:gravity="center_vertical"
                                android:hint="@string/hint_car_ticket_end_time"
                                android:text="17:35"
                                android:textSize="24sp"
                                android:fontFamily="sans-serif-thin"
                                android:inputType="none"
                                />
                    </android.support.design.widget.TextInputLayout>


                    <ImageButton
                            android:id="@+id/btn_car_set_end_time"
                            android:src="@mipmap/ic_access_time_white_24dp"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:hint="@string/action_pick_time"
                            android:fontFamily="sans-serif-thin"
                            android:layout_gravity="center_vertical"
                            />
                </TableRow>
            </TableLayout>

            <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    >
                <EditText
                        android:id="@+id/edit_car_model"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="center_vertical"
                        android:hint="@string/hint_car_model"
                        android:textSize="24sp"
                        android:fontFamily="sans-serif-thin"
                        android:layout_gravity="left"
                        />

            </android.support.design.widget.TextInputLayout>

            <android.support.design.widget.TextInputLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    >
                <EditText
                        android:id="@+id/edit_car_notes"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:gravity="bottom"
                        android:lines="4"
                        android:hint="@string/hint_car_notes"
                        android:textSize="18sp"
                        android:fontFamily="sans-serif-thin"
                        android:layout_gravity="left"
                        />

            </android.support.design.widget.TextInputLayout>

        </LinearLayout>

    </ScrollView>

    <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="fill_parent">

        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_alignParentBottom="true"
                android:orientation="horizontal">

            <ImageView
                    android:layout_width="@dimen/car_preview_size"
                    android:layout_height="@dimen/car_preview_size"
                    android:src="@mipmap/ic_launcher"/>

            <ImageView
                    android:layout_width="@dimen/car_preview_size"
                    android:layout_height="@dimen/car_preview_size"
                    android:src="@mipmap/ic_launcher"/>

            <ImageView
                    android:layout_width="@dimen/car_preview_size"
                    android:layout_height="@dimen/car_preview_size"
                    android:src="@mipmap/ic_launcher"/>

        </LinearLayout>

    </RelativeLayout>

</LinearLayout>

这是清单:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="com.demo" >

    <application
        android:allowBackup="true"
        android:icon="@mipmap/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name=".MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />
                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>
        <activity
            android:name=".ItemEditActivity"
            android:parentActivityName=".MainActivity" />
        <activity

    </application>

</manifest>

0 个答案:

没有答案