CollapsingToolbarLayout:透明状态栏和边距

时间:2018-02-20 06:44:57

标签: margin toolbar android-coordinatorlayout android-collapsingtoolbarlayout

我在我的应用中使用Appbar和CollapsingToolbarLayout,我需要让我的状态栏透明并在下方显示图片。我是这样做的:

if (findViewById(R.id.rl_home_root) != null) {
                    CoordinatorLayout.LayoutParams params = new CoordinatorLayout.LayoutParams(CoordinatorLayout.LayoutParams.MATCH_PARENT, CoordinatorLayout.LayoutParams.MATCH_PARENT);
                    params.setMargins(0, -Utils.getStatusBarHeight(), 0, 0); //setting negative margin to root CL, important
                    findViewById(R.id.rl_home_root).setLayoutParams(params);
                }

                getWindow().getDecorView().setSystemUiVisibility(
                        View.SYSTEM_UI_FLAG_LAYOUT_STABLE
                                | View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN);
                getWindow().setStatusBarColor(Color.TRANSPARENT);

它工作正常,但我有一个问题 - 我从RestAPI服务收到Appbar图片,我不知道它的大小。所以我应该使用centerCrop scaleType。有一个问题: enter image description here

正如您所看到的,我的Appbar图片和RecyclerView之间有一些空间。我试图从根CL中移除我的负上边距,但它只会将所有内容移动一点点,并使我的状态栏为colorPrimary,空橙色空间仍然在这里。有什么建议如何解决这个问题?

0 个答案:

没有答案