使软键盘的行为类似于Android中的IOS [英] Make soft keyboard behave like IOS in Android

查看:94
本文介绍了使软键盘的行为类似于Android中的IOS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个布局,我将小部件与weight属性按比例放置.我不想使用scrollView,而是希望我的小部件根据其重量适合屏幕.

I have a layout which I placed my widgets proportionally with weight attribute. I don't want to use scrollView, I want my widgets to fit onto screen according to their weights.

但是,我希望我的布局在弹出软键盘时可滚动.我不希望调整它的大小,因此不能使用android:windowSoftInputMode="adjustResize"

However, I want my layout to be scrollable when soft keyboard pops up. I don't want it to be resized so I can't use android:windowSoftInputMode="adjustResize"

我尝试了android:windowSoftInputMode="adjustPan",它将edittext字段移到了软键盘上方.但是,这次它不滚动,我必须关闭软键盘以选择下一个EditText字段.我知道通过添加输入类型,我可以在键盘上具有前进按钮.但是,我不想只依赖于此,我也希望它可以滚动而不像在IOS中那样调整大小.

I tried android:windowSoftInputMode="adjustPan" and it moves the edittext field above the soft keyboard. However, this time it does not scroll and I have to close soft keyboard to choose next EditText field.I know that by adding input type, I can have forward buttons on my keyboard. However, I don't want to depend on that only, I also want it to be scrollable without resizing like in IOS.

我能做到吗?如果可以,请您向我解释一下吗?

Can I achieve that? If yes, could you explain this to me , please?

这是我的布局:

<LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/bg"
    android:orientation="vertical"
    android:weightSum="20">

    <LinearLayout
        android:layout_width="0px"
        android:layout_height="0px"
        android:focusable="true"
        android:focusableInTouchMode="true" />

    <FrameLayout
        android:id="@+id/imagelogin"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_gravity="center"
        android:layout_weight="12"
        android:gravity="center">


        <ImageView
            android:id="@+id/image"
            android:layout_width="300dp"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:gravity="center"
            android:src="@drawable/logo_home" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="40dp"
            android:layout_gravity="bottom"
            android:layout_marginLeft="10dp"
            android:layout_marginRight="10dp"
            android:orientation="horizontal"
            android:weightSum="2">

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginRight="5dp"
                android:layout_weight="1"
                android:background="@color/material_blue_grey_800"
                android:gravity="center"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Tab 1"
                    android:textColor="@android:color/white"
                    android:textSize="20sp" />

            </LinearLayout>

            <LinearLayout
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_marginLeft="5dp"
                android:layout_weight="1"
                android:gravity="center"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Tab 2"
                    android:textColor="@android:color/white"
                    android:textSize="20sp" />

            </LinearLayout>

        </LinearLayout>

        <include
            android:id="@+id/toolbar"
            layout="@layout/app_bar"></include>

    </FrameLayout>

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="8">

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

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 1" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 1" />

            <EditText
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:hint="Input 1" />

        </LinearLayout>

    </FrameLayout>
</LinearLayout>

这是它的外观:

推荐答案

该功能未内置于Android中.如果需要的话,您需要将整个布局放在滚动视图中.

That functionality isn't built into Android. If you want that, you need to put your entire layout inside of a scroll view.

这篇关于使软键盘的行为类似于Android中的IOS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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