Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sample “UseInFragmentActivity”,ImageFrament不在viewpager的第一页时,切换到ImageFrament整个屏幕往上移动了一个状态栏高度 #53

Closed
Chen-Sir opened this issue Oct 21, 2016 · 10 comments

Comments

@Chen-Sir
Copy link

ImageFrament不放在viewpager的第一页时,切换到ImageFrament时整个界面往上移动了一个状态栏高度(底部冒出一个高度为状态栏高度的白色的view)。添加fragment代码如下:
mFragmentList.add(new SimpleFragment());

mFragmentList.add(new ImageFragment());

mFragmentList.add(new SimpleFragment());
mFragmentList.add(new SimpleFragment());
并且UseInFragmentActivity的setStatusBar方法改为如下:
protected void setStatusBar() {
StatusBarUtil.setColor(UseInFragmentActivity.this, ContextCompat.getColor(this, R.color.colorAccent), 0);

    //isFullScreen = true;
    //StatusBarUtil.setTranslucentForImageViewInFragment(UseInFragmentActivity.this,0, null);
}

其他代码未变动。

@laobie
Copy link
Owner

laobie commented Oct 21, 2016

不在第一个的时候确实需要自己再调整一下的,参照我的处理,自己对界面做一点处理,这里只是给个用例,不能给出所有的用例

@laobie
Copy link
Owner

laobie commented Oct 21, 2016

@Chen-Sir 你可以再切换到 imageFragment 时给界面设置一个状态栏高度的偏移

@Chen-Sir
Copy link
Author

@laobie 它为什么往上移了一小段距离呢?这个地方不是很理解。

@laobie
Copy link
Owner

laobie commented Oct 21, 2016

@Chen-Sir 看到你的邮件了,明天我抽空看一下

@canhuah
Copy link

canhuah commented Oct 24, 2016

可以给你其他fragment的最上面添加一个View
<View
android:background="@color/main_red" //你想设置的颜色
android:layout_width="match_parent"
android:layout_height="@dimen/statusbar_height"/> //状态栏的高度

之后在values-v19 dimens.xml中定义statusbar_height = 25dp
在vlues 下定义statusbar_height = 0dp
意为API>=19以上高度为25dp(状态栏高度) 以下高度为0dp

@Chen-Sir
Copy link
Author

@laobie 嗯,我周末就搞定这个问题了,有点忙,没来及回复issues。本想推个PR,但想想问题也比较简单,就算了。上面那个方法,我看了并试了下,可以的,方法很好。不过我用的是另外一种方式。我修改了你的源码。
我再把我遇到的问题详细复述下:在5.0版本以上,在Sample的UseInFragmentActivity中(即在同一个activity中),从第一页切换到第二页时(setColor方法切换到setTranslucentForImageViewInFragment时),ImageFragment(第二页)界面整体往上移动了一点高度,在你的Sample中的表现是底部的BottomBar非常快速的上下抖动了一下,看样子是界面本来往上移了一点,但是又快速重绘了,占满了屏幕。以上问题,均保持UseInFragmentActivity中的代码不变,仅仅修改setStatusBar方法和调整ImageFragment位置

我的解决办法是:在StatusBarUtil类的setTransparentForWindow方法改为如下:

private static void setTransparentForWindow(Activity activity) {
    if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
        activity.getWindow().setStatusBarColor(Color.TRANSPARENT);
        activity.getWindow()
            .getDecorView()
            .setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_STABLE | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);

        Window window = activity.getWindow();
        ViewGroup mContentView = (ViewGroup) window.findViewById(Window.ID_ANDROID_CONTENT);
        View mChildView = mContentView.getChildAt(0);
        if (mChildView != null) {
            ViewCompat.setOnApplyWindowInsetsListener(mChildView, new OnApplyWindowInsetsListener() {
                @Override
                public WindowInsetsCompat onApplyWindowInsets(View v, WindowInsetsCompat insets) {
                    return insets;
                }
            });
            ViewCompat.setFitsSystemWindows(mChildView, false);
            ViewCompat.requestApplyInsets(mChildView);
        }
    } else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
       .........
       //不变
    }
}

这样,ImageFragment会立即适应屏幕,使用本库时,5.0版本以上不会发生闪动或者底部冒出一截空白view。经测试,修改代码后,并未影响Sample中其他示例的效果。

其实UseInFragmentActivity中的resetFragmentView方法逻辑可以加到StatusBarUtil中,我试过。这样用起来更傻瓜一点。不过也无所谓,自己加些逻辑也没问题。

@Chen-Sir
Copy link
Author

@canhuah 方法很好!谢谢!

@laobie
Copy link
Owner

laobie commented Oct 25, 2016

@Chen-Sir ok,你这样的使用看起来也不错,不知道切换过程中怎么样,昨天一开始和楼上那个哥们讨论时我也尝试在工具类上做修改,但是修改完了感觉效果还是差点,后来就想着把颜色状态栏的界面也当成图片界面处理,这样就少了切换的过程,整个 viewpager 的滑动很切换看起来都很好,而且管理起来也不错。
谢谢探讨~

@Chen-Sir
Copy link
Author

@laobie 嗯,我也觉得可以合为一起,少了切换过程。用起来也不用写什么判断逻辑了(迷之缩进毁一生233)。我主要是觉得Library这东西,用起来越简单越好。

@tt328307109
Copy link

66666

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants