android:fitsSystemWindows不在工具栏上工作

时间:2015-04-24 18:00:25

标签: android toolbar android-4.4-kitkat

我正在使用来自ksoichiro的Android库Android-ObservableScrollView。我使用他的示例灵活空间与viewpager,我修改它。 但是有一些问题。你可以在我的xml中看到有2个android:fitsSystemWindows。一个在LinearLayout中,另一个在工具栏中。在LinearLayout中工作得很好。但在工具栏中不起作用。为什么会这样? 谢谢。抱歉我的英文不好

theres my xml code:

<FrameLayout 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">

<com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout
    android:id="@+id/container"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <ImageView
        android:id="@+id/image"
        android:layout_width="match_parent"
        android:layout_height="@dimen/flexible_background"
        android:scaleType="centerCrop"
        android:src="@drawable/bridge" />

    <View
        android:id="@+id/overlay"
        android:layout_width="match_parent"
        android:layout_height="@dimen/flexible_background"
        android:background="?attr/colorPrimary" />

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        android:fitsSystemWindows="true">

        <FrameLayout
            android:id="@+id/header"
            android:layout_width="match_parent"
            android:layout_height="@dimen/flexible_height">

            <TextView
                android:id="@+id/title"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:layout_gravity="bottom"
                android:layout_margin="@dimen/abc_action_bar_default_padding_material"
                android:ellipsize="end"
                android:gravity="center_vertical"
                android:maxLines="1"
                android:minHeight="?attr/actionBarSize"
                android:textColor="@android:color/white"
                android:textSize="20sp" />
        </FrameLayout>

        <com.bright.nongkrongyuk.ui.SlidingTabLayout
            android:id="@+id/sliding_tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:background="@android:color/black"
            app:sliding_textColor="@drawable/sliding_tab_profile" />

        <android.support.v4.view.ViewPager
            android:id="@+id/pager"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:background="@android:color/background_light" />
    </LinearLayout>
</com.github.ksoichiro.android.observablescrollview.TouchInterceptionFrameLayout>

<android.support.v7.widget.Toolbar
    android:id="@+id/toolbar"
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize"
    android:background="@android:color/transparent"
    android:minHeight="?attr/actionBarSize"
    android:fitsSystemWindows="true" />
</FrameLayout>

1 个答案:

答案 0 :(得分:13)

android:fitsSystemWindows属性设置填充。这意味着拟合适用于子视图。您必须将其应用于FrameLayout或将Toolbar置于嵌套Layout

使用适合屏幕的视图制作正确的全屏布局真的很棘手。我将Fragment子类化,我可以声明一个内容视图,它将根据Status-和/或Navigationbar获得填充