Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fitsSystemWindows and extra padding on kitkat

I have a ListView in an activity with an actionbar like this:

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

The activity theme have:

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

Under Kitkat devices, the behaviour is what I want: the items have 10dp padding at the bottom and at the top. On kitkat devices the paddingTop and paddingBottom seem to have no efect as the ListView's item do not have the 10dp padding at the top and bottom.

I think the problem is somewhere in android:fitsSystemWindows as this attribute seem to set the necessary padding to the view because of translucent decor and make the android:padding* attributes being ignored.

My question: is there anyway so I can have the android:fitsSystemWindows set to true and still add extra padding on the view?

like image 498
Noeljunior Avatar asked Jun 05 '14 11:06

Noeljunior


2 Answers

You should add this attribute to parent view :

<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" >
like image 78
RuNo280 Avatar answered Nov 20 '22 10:11

RuNo280


You can create your own class that extends ListView and override fitSystemWindows() in that class, in order to add the insets to the existing padding (the default implementation replaces any padding with the insets). Then you don't need to specify the android:fitsSystemWindows attribute in the layout XML because your new implementation will always be called.

like image 42
BladeCoder Avatar answered Nov 20 '22 10:11

BladeCoder