适合SystemWindows和kitkat上的额外填充

时间:2014-06-05 11:31:20

标签: android android-4.4-kitkat translucentdecor

我在活动中有一个ListView,其动作栏如下:

<LinearLayout
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:android="http://schemas.android.com/apk/res/android"
    tools:context=".LauncherActivity"

    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    >
        <ListView
            android:id="@+id/lvcalendar"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:clipToPadding="false"
            android:fitsSystemWindows="true"


            android:dividerHeight="10dp"
            android:paddingTop="10dp"
            android:paddingBottom="10dp"
            android:divider="#00ffffff"

            android:scrollbarThumbVertical="@drawable/scrollbarstyle"
            android:layout_gravity="top"
            android:listSelector="@android:color/transparent"
            />
</LinearLayout>

活动主题包括:

<item name="android:windowTranslucentStatus">true</item>
<item name="android:windowTranslucentNavigation">true</item>

在Kitkat设备下,行为就是我想要的:这些项目在底部和顶部都有10dp填充。在kitkat设备上,paddingTop和paddingBottom似乎没有效果,因为ListView的项目在顶部和底部没有10dp填充。

我认为问题出现在android:fitsSystemWindows中,因为此属性似乎为视图设置了必要的填充,因为半透明的装饰会使android:padding*属性被忽略。

我的问题:无论如何,我可以将android:fitsSystemWindows设置为true并仍然在视图上添加额外的填充?

4 个答案:

答案 0 :(得分:14)

您应该将此属性添加到父视图中:

<LinearLayout
xmlns:tools="http://schemas.android.com/tools"
xmlns:android="http://schemas.android.com/apk/res/android"
tools:context=".LauncherActivity"
android:fitsSystemWindows="true"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >

答案 1 :(得分:1)

您可以创建自己的类来扩展ListView并覆盖该类中的fitSystemWindows(),以便将插入添加到现有的填充(默认实现将替换任何使用插入的填充)。然后,您不需要在布局XML中指定android:fitsSystemWindows属性,因为将始终调用新的实现。

答案 2 :(得分:0)

答案是否定的。如果将android:fitsSystemWindows设置为true,则会覆盖该视图的填充。

你可以通过两个嵌套视图来实现你想要的行为,其中父视图有android:fitsSystemWindows为true而另一个包含填充。

答案 3 :(得分:-1)

使用时:

fitsSystemWindows=true

对于布局,填充将重置为insets。您可以使用FitsSystemWindowsFrameLayout来解决此默认行为。

相关问题