显示键盘时,除了某些视图外,上推内容 [英] Push up content except some view when keyboard shown

查看:70
本文介绍了显示键盘时,除了某些视图外,上推内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的布局底部包含5个EditText和一个ButtonTextView.现在,当我按下EditText时,将显示键盘,并且 all (我的View)被向上推.

I have a layout that contains 5 EditText and a Button and a TextView at bottom. Now when I press an EditText then the keyboard will shown and all my View is push up.

现在,我不想将TextViewButton推到键盘上方,只想ScrollView内的所有推杆 EditText推到键盘上方.

Now I don't want to push my TextView and Button to above keyboard, just only want to push up all EditText inside ScrollView to above keyboard.

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    >

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="1"
        android:background="#ff0"
        >

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

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 1"

                />

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 2"
                />

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 3"
                />

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 4"
                />

            <EditText
                android:layout_marginTop="30dp"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="EditText 5"
                android:inputType="textNoSuggestions"
                />

        </LinearLayout>

    </ScrollView>

    <Button
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:text="Button"
        />
    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:textColor="#000"
        android:text="I don't want to push this TextView and Button to above keyboard when keyboard is shown. Just obly want to push the ScrollView that contain all EditText"
        />
</LinearLayout>

我有一个主意.当我在监听器时会显示和隐藏键盘.当键盘显示时,我将设置ScrollView的底部边距=键盘高度,当键盘隐藏时,我将设置此边距=0.
有什么方法可以更轻松地处理我的案件?任何帮助或建议将不胜感激.

I have an idea is. When I will listener when keyboard show and hide. When keyboard show I will set the bottom margin of ScrollView = keyboard height, when keyboard hide I will set this margin = 0.
Is there any way easier to handle my case? Any help or suggestion would be great appreciated.

更新
如果我使用windowSoftInputMode=adjustPan =>并非所有EditText都向上推到键盘上方
如果我使用windowSoftInputMode=adjustResize => ButtonTextView,并且所有EditText都向上推到键盘上方

UPDATE
If I use windowSoftInputMode=adjustPan => not all EditText is push up to above keyboard
If I use windowSoftInputMode=adjustResize => Button, TextView and all EditText is push up to above keyboard

推荐答案

  1. 在所有Nexus移动设备和平板电脑设备上进行了测试.它工作正常.我正在使用您的布局xml代码,并且仅向视图添加了ID.

  1. Tested on all Nexus mobile and Tablet devices. It works fine. I am using your layout xml code and have added only id's to views.

我在生产应用程序中使用下面的库,这是非常有前途的.为了达到相同的目的,并在应用程序gradle中添加以下行: 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.0.1' 此处是相同链接.

I am using the below library in my production application and it is very promising. To achieve the same and add the below line in app gradle: 'net.yslibrary.keyboardvisibilityevent:keyboardvisibilityevent:2.0.1' Here is the link for the same.

有关其余代码,请参见以下要点:清单代码,活动代码,活动布局代码.

Refer to the below gist for the rest of the code:Manifest code, Activity code, Activity layout code.

这篇关于显示键盘时,除了某些视图外,上推内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆