fitsSystemWindows and extra padding on kitkat
Asked Answered
O

5

7

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?

Oppugnant answered 5/6, 2014 at 11:31 Comment(4)
please check the answer as Accepted ! , what's Wrong ?Elin
The behaviour I want is not what @Spirit said.Oppugnant
did you find solution already? got the same problemInstructor
No. I actually forgot this question here. I'm the owner of this question and I'm not allowed to down vote the solutions that I tested that don't work? This stackoverflow is just useless like that. Anyway, other people just up voted in something that is not the solution. Still, useless place to share questions and answers.Oppugnant
L
14

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" >
Langevin answered 5/6, 2014 at 12:31 Comment(1)
If add this to the parent activity, the listview won't fill the navigation bar. I still want to have the listview behind the translucent navigation bar but the I want to have the extra padding plus the fitsSystemWindows' padding. It may be not possible, I don't know. If you need more info or screenshoots just say. ThanksOppugnant
G
1

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.

Guinn answered 19/6, 2014 at 0:20 Comment(1)
It seems that's what I need. I'll try as soon as possible and I'll tell here the results and solution. Thanks!Oppugnant
H
0

Answer is no. If you set android:fitsSystemWindows as true, it overwrites padding of that view.

You can achieve the behavior you want by having two nested views, where the parent view has android:fitsSystemWindows as true and other contains the padding.

Houdini answered 22/5, 2016 at 20:9 Comment(0)
R
0

Move your android:fitsSystemWindows="true" to your parent ListView

Ramrod answered 19/5, 2021 at 9:7 Comment(0)
P
-1

When you use:

fitsSystemWindows=true

To a layout, padding will be reset to insets. You can use the FitsSystemWindowsFrameLayout to solve this default behavior.

Pinhole answered 4/7, 2016 at 2:43 Comment(1)
A link to a potential solution is always welcome, but please add context around the link so your fellow users will have some idea what it is and why it’s there. Always quote the most relevant part of an important link, in case the target site is unreachable or goes permanently offline. Take into account that being barely more than a link to an external site is a possible reason as to Why and how are some answers deleted?.Neoclassic

© 2022 - 2024 — McMap. All rights reserved.