SwipeRefreshLayout被透明状态栏遮挡在ActionBar后面。

11

当我在使用透明导航栏和状态栏(API Level 19)时,我发现我的SwipeRefreshLayout不可见。也就是说,它目前处于状态栏下方(屏幕顶部),而我希望它处于操作栏下方。

ListView的显示效果正常。也就是说,内容可以正确地显示在导航栏后面,且不会被隐藏在状态栏或操作栏下面。

话虽如此,如果我在相对布局中添加android:fitsSystemWindows="true"属性,则SwipeRefreshLayout将可以正常工作。但是,这样做会使得我的ListView无法在透明的导航栏下方显示。相反,导航栏仅仅是我的背景颜色,并且不允许来自ListView的内容显示在其下方。

我该如何保持ListView的当前状态,同时让SwipeRefreshLayout可见(而不是被隐藏在屏幕顶部的状态栏下面)?

以下是我的布局:

<android.support.v4.widget.DrawerLayout
        xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:tools="http://schemas.android.com/tools"
        android:id="@+id/drawer_layout"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <RelativeLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:paddingTop="10dp"
            android:background="#ccc"
            android:clipToPadding="false">

            <android.support.v4.widget.SwipeRefreshLayout
                android:id="@+id/swipe_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent">

            <FrameLayout
                android:id="@+id/container"
                android:paddingLeft="@dimen/activity_horizontal_margin"
                android:paddingRight="@dimen/activity_horizontal_margin"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:background="#ccc">

                <ListView
                    android:layout_width="fill_parent"
                    android:layout_height="fill_parent"
                    android:id="@+id/listView"
                    android:paddingTop="10dp"
                    android:fitsSystemWindows="true"
                    android:clipToPadding="false"
                    android:divider="@android:color/transparent"
                    android:layout_gravity="left|top" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceLarge"
                    android:text="No Internet Connection"
                    android:id="@+id/noInternet"
                    android:textColor="@android:color/secondary_text_light"
                    android:layout_gravity="center" />

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:textAppearance="?android:attr/textAppearanceMedium"
                    android:text="Pull To Refresh"
                    android:translationY="20dp"
                    android:id="@+id/nointernetSub"
                    android:textColor="@android:color/secondary_text_light"
                    android:layout_gravity="center" />

            </FrameLayout>

            </android.support.v4.widget.SwipeRefreshLayout>

        </RelativeLayout>

    <fragment android:id="@+id/navigation_drawer"
        android:layout_width="@dimen/navigation_drawer_width"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:name="com.package.app.NavigationDrawerFragment"
        tools:layout="@layout/fragment_navigation_drawer" />

</android.support.v4.widget.DrawerLayout>

1
你的问题已经很久了,但也许你仍然需要一个答案。看一下这个:https://dev59.com/22Af5IYBdhLWcg3wqEHp - Naroh
1个回答

4
我建议使用边距。
android:layout_marginTop="?android:attr/actionBarSize"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接