出现软键盘时,布局不会向上推

时间:2017-12-01 04:16:33

标签: android android-layout android-softkeyboard

我设计了this布局,取自this的引用,下面是相同的代码。

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/ll_parent"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#FFFFFF"
    android:orientation="vertical">
    <android.support.v7.widget.Toolbar
        android:id="@+id/toolbar"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/action_bar_color"
        android:minHeight="?attr/actionBarSize">

        <TextView
            android:id="@+id/txt_user_name"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="left"
            android:layout_marginLeft="@dimen/image_margin_left"
            android:text="@string/app_name"
            android:textColor="@android:color/black"
            android:textSize="@dimen/login_txt_size" />

        <ImageView
            android:id="@+id/img_refresh"
            android:layout_width="@dimen/logo_image_w"
            android:layout_height="@dimen/logo_image_h"
            android:layout_gravity="right"
            android:layout_marginLeft="@dimen/image_margin_left"
            android:background="@drawable/custom_image_click"
            android:src="@drawable/ic_action_refresh" />

        <ImageView
            android:id="@+id/img_setting"
            android:layout_width="@dimen/logo_image_w"
            android:layout_height="@dimen/logo_image_h"
            android:layout_gravity="right"
            android:layout_marginLeft="@dimen/image_margin_left"
            android:background="@drawable/custom_image_click"
            android:src="@drawable/ic_action_settings" />

        <ImageView
            android:id="@+id/img_wifi"
            android:layout_width="@dimen/logo_image_w"
            android:layout_height="@dimen/logo_image_h"
            android:layout_gravity="right"
            android:layout_marginLeft="@dimen/image_margin_left"
            android:background="@drawable/custom_image_click"
            android:src="@drawable/ic_wifi_on"
            android:tint="@color/button_theme_color" />

    </android.support.v7.widget.Toolbar>
    <TextView
        android:id="@+id/tv_home_networkStatus"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="#003b60"
        android:gravity="center_horizontal"
        android:padding="10dp"
        android:text="Medium Text"
        android:textColor="#FFFF0000"
        android:textSize="20sp"
        android:visibility="visible" />

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1"
        android:fillViewport="true"
        android:gravity="center">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="10">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="4">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_margin="50dp"
                    android:src="@drawable/logo_login" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="100dp"
                android:layout_marginRight="100dp"
                android:layout_weight="6"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/round_masjid_corner"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="20dp"
                        android:src="@drawable/masjid" />

                    <View
                        android:layout_width="5dp"
                        android:layout_height="match_parent"
                        android:background="@drawable/user_sep" />

                    <EditText
                        android:id="@+id/edt_clientid"
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="10dp"
                        android:background="@null"
                        android:hint="Client ID"
                        android:inputType="number"
                        android:singleLine="true"
                        android:textColor="#FFFFFF"
                        android:textColorHint="#FFFFFF"
                        android:textSize="35sp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/round_kiosk_corner"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@null"
                        android:padding="20dp"
                        android:src="@drawable/tablet" />

                    <View
                        android:layout_width="5dp"
                        android:layout_height="match_parent"
                        android:background="@drawable/pass_sep" />

                    <EditText
                        android:id="@+id/edt_device_code"
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="10dp"
                        android:background="@null"
                        android:hint="Device Code"
                        android:inputType="text"
                        android:singleLine="true"
                        android:textColor="#FFFFFF"
                        android:textColorHint="#FFFFFF"
                        android:textSize="35sp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/btn_login"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"

                        android:layout_weight="1"
                        android:background="@drawable/custom_button_frag_menu"
                        android:padding="20dp"
                        android:text="Login"
                        android:textAllCaps="false"
                        android:textColor="#FFFFFF"
                        android:textSize="35sp" />

                    <Button
                        android:id="@+id/btn_cancel"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"

                        android:layout_weight="1"
                        android:background="@drawable/custom_button_frag_menu"
                        android:padding="20dp"
                        android:text="Cancel"
                        android:textAllCaps="false"
                        android:textColor="#FFFFFF"
                        android:textSize="35sp" />
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>
    </ScrollView>



</LinearLayout>

清单代码在

之下
 <activity android:name=".activity.LoginActivity"
            android:theme="@style/AppTheme.NoActionBar"
            android:screenOrientation="landscape"

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

但它仍然提供this之类的输出。当软键盘出现时,按钮隐藏在软键盘的下方。我尝试使用adjustResize以及adjustPan,但输出仍然没有变化。我也添加了ScrollView如果任何人都有解决方案请帮助

1 个答案:

答案 0 :(得分:8)

尝试将此ScrollView设为父根布局,如下面的代码

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/ll_parent"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#FFFFFF"
        android:orientation="vertical">

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/action_bar_color"
            android:minHeight="?attr/actionBarSize">

            <TextView
                android:id="@+id/txt_user_name"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_gravity="left"
                android:layout_marginLeft="@dimen/image_margin_left"
                android:text="@string/app_name"
                android:textColor="@android:color/black"
                android:textSize="@dimen/login_txt_size" />

            <ImageView
                android:id="@+id/img_refresh"
                android:layout_width="@dimen/logo_image_w"
                android:layout_height="@dimen/logo_image_h"
                android:layout_gravity="right"
                android:layout_marginLeft="@dimen/image_margin_left"
                android:background="@drawable/custom_image_click"
                android:src="@drawable/ic_action_refresh" />

            <ImageView
                android:id="@+id/img_setting"
                android:layout_width="@dimen/logo_image_w"
                android:layout_height="@dimen/logo_image_h"
                android:layout_gravity="right"
                android:layout_marginLeft="@dimen/image_margin_left"
                android:background="@drawable/custom_image_click"
                android:src="@drawable/ic_action_settings" />

            <ImageView
                android:id="@+id/img_wifi"
                android:layout_width="@dimen/logo_image_w"
                android:layout_height="@dimen/logo_image_h"
                android:layout_gravity="right"
                android:layout_marginLeft="@dimen/image_margin_left"
                android:background="@drawable/custom_image_click"
                android:src="@drawable/ic_wifi_on"
                android:tint="@color/button_theme_color" />

        </android.support.v7.widget.Toolbar>

        <TextView
            android:id="@+id/tv_home_networkStatus"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#003b60"
            android:gravity="center_horizontal"
            android:padding="10dp"
            android:text="Medium Text"
            android:textColor="#FFFF0000"
            android:textSize="20sp"
            android:visibility="visible" />


        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="horizontal"
            android:weightSum="10">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="4">

                <ImageView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_gravity="center"
                    android:layout_margin="50dp"
                    android:src="@drawable/logo_login" />
            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="wrap_content"
                android:layout_gravity="center"
                android:layout_marginLeft="100dp"
                android:layout_marginRight="100dp"
                android:layout_weight="6"
                android:orientation="vertical">

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:background="@drawable/round_masjid_corner"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:padding="20dp"
                        android:src="@drawable/masjid" />

                    <View
                        android:layout_width="5dp"
                        android:layout_height="match_parent"
                        android:background="@drawable/user_sep" />

                    <EditText
                        android:id="@+id/edt_clientid"
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="10dp"
                        android:background="@null"
                        android:hint="Client ID"
                        android:inputType="number"
                        android:singleLine="true"
                        android:textColor="#FFFFFF"
                        android:textColorHint="#FFFFFF"
                        android:textSize="35sp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:background="@drawable/round_kiosk_corner"
                    android:orientation="horizontal">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:contentDescription="@null"
                        android:padding="20dp"
                        android:src="@drawable/tablet" />

                    <View
                        android:layout_width="5dp"
                        android:layout_height="match_parent"
                        android:background="@drawable/pass_sep" />

                    <EditText
                        android:id="@+id/edt_device_code"
                        android:layout_width="fill_parent"
                        android:layout_height="match_parent"
                        android:layout_marginLeft="10dp"
                        android:background="@null"
                        android:hint="Device Code"
                        android:inputType="text"
                        android:singleLine="true"
                        android:textColor="#FFFFFF"
                        android:textColorHint="#FFFFFF"
                        android:textSize="35sp" />
                </LinearLayout>

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:layout_marginTop="20dp"
                    android:orientation="horizontal">

                    <Button
                        android:id="@+id/btn_login"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"

                        android:layout_weight="1"
                        android:background="@drawable/custom_button_frag_menu"
                        android:padding="20dp"
                        android:text="Login"
                        android:textAllCaps="false"
                        android:textColor="#FFFFFF"
                        android:textSize="35sp" />

                    <Button
                        android:id="@+id/btn_cancel"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:layout_gravity="center"

                        android:layout_weight="1"
                        android:background="@drawable/custom_button_frag_menu"
                        android:padding="20dp"
                        android:text="Cancel"
                        android:textAllCaps="false"
                        android:textColor="#FFFFFF"
                        android:textSize="35sp" />
                </LinearLayout>

            </LinearLayout>

        </LinearLayout>


    </LinearLayout>

</ScrollView>

将清单文件中的 android:windowSoftInputMode="adjustResize" 应用于您的活动

注意: - fullscreen mode doesn't resize