V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
ilumer
V2EX  ›  Android

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

  •  
  •   ilumer · 2016-07-16 00:34:46 +08:00 · 11404 次点击
    这是一个创建于 2842 天前的主题,其中的信息可能已经有所发展或是发生改变。

    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 上却是正常的,希望可以指明一下哪里有问题。手机图片

    8 条回复    2016-07-16 15:09:27 +08:00
    cppgohan
        1
    cppgohan  
       2016-07-16 00:54:50 +08:00
    我看出来的一点是 ViewPager 高度应该 match_parent
    hackerwgf
        2
    hackerwgf  
       2016-07-16 09:21:57 +08:00 via iPhone
    是指 viewpager 和 toolbar 之间的那个缝隙嘛?
    zhaohui318
        3
    zhaohui318  
       2016-07-16 09:26:10 +08:00
    AppBarLayout 里面的 fitsSystemWindows 去掉试试
    ilumer
        4
    ilumer  
    OP
       2016-07-16 09:56:28 +08:00 via Android
    @hackerwgf 对的一直存在,但是在 4.4 的魅族上就没有
    L4D
        5
    L4D  
       2016-07-16 10:03:44 +08:00 via Android
    viewpager 里面的 view 是不是设了 margin 或 padding
    ilumer
        6
    ilumer  
    OP
       2016-07-16 11:41:07 +08:00 via Android
    @zhaohui318 谢谢你的帮助,我看了一下 fitsystemwibdow 的介绍,没有理解为什么会出现这个问题。
    zhaohui318
        7
    zhaohui318  
       2016-07-16 14:49:30 +08:00
    fitsystemwibdow="true" 会使控件增加一个 状态栏的高度, 具体表现不同的版本出入很大,透明状态栏想要适配完美是一个难题。
    ilumer
        8
    ilumer  
    OP
       2016-07-16 15:09:27 +08:00 via Android
    @zhaohui318 看来我理解错了,我看网上的解释是这个属性属性必须用在 content view 的根 view 中,尽管所有的 view 都可以添加这个属性。
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2309 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 16:11 · PVG 00:11 · LAX 09:11 · JFK 12:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.