本文介绍了出现软键盘时,布局没有向上推的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我设计了布局,方法是从及其代码如下.

I have designed layout by taking the reference from this and code for the same is below.

    <?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>

但是它仍然给出类似.当出现软键盘时,按钮隐藏在软键盘的下面.我尝试使用adjustResizeadjustPan,但输出仍然没有变化.我也添加了ScrollView如果有人有解决方案,请帮助

But still it gives output like . When soft keyboard is appearing buttons are hiding below of the soft keyboard.I have tried by using adjustResize as well as adjustPan,but still no change in output.I have added ScrollView too If anyone is having the solution please help

推荐答案

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

Try this make ScrollView as parent root layout like below code

<?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" 应用于您的活动

than apply android:windowSoftInputMode="adjustResize" in manifest file to your activity

注意:-

这篇关于出现软键盘时,布局没有向上推的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 15:56