AppBarLayout+Toolbar+TabLayout 使用时出现空白区域。

2016-07-16 00:34:46 +08:00
 ilumer

main.xml

    <?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true">

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

        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:elevation="4dp"
            app:layout_scrollFlags="scroll|enterAlways"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light"/>

        <android.support.design.widget.TabLayout
            android:id="@+id/tabLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="@color/toolbar_color" />

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

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"/>
</android.support.design.widget.CoordinatorLayout>

我是根据网上的方法来做的,在我的 6.0 的手机上会多显示一块区域,但是在 4.4 上却是正常的,希望可以指明一下哪里有问题。手机图片

11650 次点击
所在节点    Android
8 条回复
cppgohan
2016-07-16 00:54:50 +08:00
我看出来的一点是 ViewPager 高度应该 match_parent
hackerwgf
2016-07-16 09:21:57 +08:00
是指 viewpager 和 toolbar 之间的那个缝隙嘛?
zhaohui318
2016-07-16 09:26:10 +08:00
AppBarLayout 里面的 fitsSystemWindows 去掉试试
ilumer
2016-07-16 09:56:28 +08:00
@hackerwgf 对的一直存在,但是在 4.4 的魅族上就没有
L4D
2016-07-16 10:03:44 +08:00
viewpager 里面的 view 是不是设了 margin 或 padding
ilumer
2016-07-16 11:41:07 +08:00
@zhaohui318 谢谢你的帮助,我看了一下 fitsystemwibdow 的介绍,没有理解为什么会出现这个问题。
zhaohui318
2016-07-16 14:49:30 +08:00
fitsystemwibdow="true" 会使控件增加一个 状态栏的高度, 具体表现不同的版本出入很大,透明状态栏想要适配完美是一个难题。
ilumer
2016-07-16 15:09:27 +08:00
@zhaohui318 看来我理解错了,我看网上的解释是这个属性属性必须用在 content view 的根 view 中,尽管所有的 view 都可以添加这个属性。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/292816

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX