Android   发布时间:2022-04-28  发布网站:大佬教程  code.js-code.com
大佬教程收集整理的这篇文章主要介绍了当使用viewpagers显示软键盘时,android移动布局大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
好吧我已经做了(我相信)我需要做的一切,使我的应用程序布局滚动/向上移动时,软键盘显示,但它不工作,所以我猜我必须有一些东西即时停止它,我想知道它是否固定的高度即时通讯给我的观看者或者我不知道的东西,我通过帖子阅读描述相对布局作为“破碎儿童视图”的键盘显示和线性布局没有破坏儿童视图,所以这里虑的是我的布局

主要活动

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout    
xmlns:android="http://scheR_742_11845@as.android.com/apk/res/android"
xmlns:app="http://scheR_742_11845@as.android.com/apk/res-auto"
xmlns:tools="http://scheR_742_11845@as.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layouT_Behavior="@String/appbar_scrolling_view_behavior"
        android:id="@+id/viewpagerHolder">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager2"
            android:layout_width="match_parent"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="8dp"
            android:layout_height="@dimen/card_pager_height" />

        <RelativeLayout
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:id="@+id/preDictsHolder"
            android:layouT_Below="@id/viewpager2">

        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager_preDicts"
            android:layout_width="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginTop="4dp"
            android:layout_height="@dimen/preDicts_pager_height" />

        </RelativeLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layouT_Below="@id/preDictsHolder"
            app:tabGravity="fill"
            android:theme="@style/CustomTabLayoutStyle" />

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layouT_Below="@id/tabs">


        <android.support.v4.view.ViewPager
            android:id="@+id/viewpager"
            android:BACkground="@color/windowBACkground"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
             />

        </LinearLayout>

    </RelativeLayout>

<android.support.design.widget.AppBarLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

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

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

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_marginTop="@dimen/card_pager_height">

    <android.support.design.widget.FloaTingActionButton
        android:id="@+id/fab2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginRight="12dp"
        android:layout_marginEnd="12dp"
        app:elevation="4dp"
        android:src="@drawable/ic_playlist_play_white_24dp"
        android:layout_gravity="right|top"
        android:layout_alignParentright="true"
        android:layout_alignParentEnd="true"/>

</RelativeLayout>

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

总共有3个浏览器,每个都有不同的布局(第一个)

一个视图

<RelativeLayout xmlns:android="http://scheR_742_11845@as.android.com/apk/res/android"
xmlns:tools="http://scheR_742_11845@as.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:BACkground="@drawable/border"
android:paddingLeft="2dp"
android:paddingRight="2dp"
tools:context=".SpeakGridDB">

<android.support.v7.widget.RecyclerView
    android:id="@+id/card_speak_grid"
    android:layout_width="match_parent"
    android:layout_gravity="center"
    android:layout_height="wrap_content"/>

</RelativeLayout>

第二个视图

<RelativeLayout xmlns:android="http://scheR_742_11845@as.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_margin="5dp"
android:paddingLeft="2dp"
android:paddingRight="2dp"
android:BACkground="@drawable/border">

<android.support.v7.widget.RecyclerView
    android:id="@+id/preDicts_card_speak_grid"
    android:layout_width="match_parent"
    android:layout_gravity="center"
    android:layout_height="wrap_content"/>

</RelativeLayout>

第三个视图

我想这个布局仍然存在当键盘弹出其当前布局的底部我把它放在一个线性布局,并尝试将其viewpager放在线性布局

<LinearLayout xmlns:android="http://scheR_742_11845@as.android.com/apk/res/android"
xmlns:tools="http://scheR_742_11845@as.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:BACkground="@color/windowBACkground"
tools:context=".oneFragment">

<android.support.v4.widget.SwiperefreshLayout
    android:id="@+id/activity_main_swipe_refresh_layout"
    android:layout_width="match_parent"
    android:BACkground="@color/windowBACkground"
    android:layout_height="wrap_content">

    <android.support.v7.widget.RecyclerView
        android:id="@+id/card_grid"
        android:BACkground="@color/windowBACkground"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:cliPTOPadding="false"/>

</android.support.v4.widget.SwiperefreshLayout>

</LinearLayout>

我也在用

android:windowSofTinputMode="adjustResize"

在我的清单中,也尝试过

android:windowSofTinputMode="adjustPan"

但是看起来像tabLayout在显示键盘时稍微向上移动但是通常顶部的两个视图保持原位并且底部一个(我想要显示一个)被键盘隐藏
任何帮助表示赞赏

updatE
仍然没有进一步这个我可以做一个固定高度的布局,并让它完美地向上滚动所示的软键盘所以没有问题,但我必须使用布局中心垂直元素,这不是我想做的我也尝试过将它全部包装在滚动视图中并使用isScrollContainer true但仍然没有任何人有任何想法的喜悦?

解决方法

我可能会搞错,但是这个问题的原因可能是已知的Android错误.

所以,首先,你需要在< activity>中添加android:windowSofTinputMode =“stateHidden | adjustResize”.标签.

其次,您需要将此类添加项目中

public class AndroidBug5497Workaround {

    // For more information,see https://code.google.com/p/android/issues/detail?id=5497
    // To use this class,simply invoke assistActivity() on an Activity that already has its content view set.

    public static void assistActivity (Activity activity) {
        new AndroidBug5497Workaround(activity);
    }
    private View mChildOfContent;
    privatE int usableHeightPrevIoUs;
    private FrameLayout.LayoutParams frameLayoutParams;

    private AndroidBug5497Workaround(Activity activity) {
        FrameLayout content = (FrameLayout)  activity.findViewById(android.R.id.content);
        mChildOfContent = content.getChildAt(0);
        mChildOfContent.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.onGlobalLayoutListener() {
            public void onGlobalLayout() {
                possiblyResizeChildOfContent();
            }
        });
        frameLayoutParams = (FrameLayout.LayoutParams) mChildOfContent.getLayoutParams();
    }

    private void possiblyResizeChildOfContent() {
        int usableHeightNow = computeUsableHeight();
        if (usableHeightNow != usableHeightPrevIoUs) {
            int usableHeightSansKeyboard = mChildOfContent.getRootView().getHeight();
            int heightDifference = usableHeightSansKeyboard - usableHeightNow;
            if (heightDifference > (usableHeightSansKeyboard/4)) {
                // keyboard probably just became visible
                frameLayoutParams.height = usableHeightSansKeyboard - heightDifference;
                } else {
                // keyboard probably just became hidden
                frameLayoutParams.height = usableHeightSansKeyboard;
            }
            mChildOfContent.requestLayout();
            usableHeightPrevIoUs = usableHeightNow;
        }
    }

    privatE int computeUsableHeight() {
        Rect r = new Rect();
        mChildOfContent.getWindowVisibleDisplayFrame(r);
        return (r.bottom - r.top);
    }

}

然后只需在包含ViewPagers的MainActivity中调用assistActivity()方法即可使用它:

@Override
protected void onCreate(Bundle savedInstanceStatE) {
    super.onCreate(savedInstanceStatE);
    setContentView(...);
    AndroidBug5497Workaround.assistActivity(this);
    ...
}

有关更多背景,请检查this线程.

大佬总结

以上是大佬教程为你收集整理的当使用viewpagers显示软键盘时,android移动布局全部内容,希望文章能够帮你解决当使用viewpagers显示软键盘时,android移动布局所遇到的程序开发问题。

如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。