Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How dismiss parent padding in children element

I have FrameLayout and for most fragments the parrent padding is good. But I have especial fragment which must not contain the padding.

<FrameLayout
    android:id="@+id/frame_content"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="10dp"
    />

<!-- My especial fragment -->
<LiearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:padding="-10dp"
/>

Any suggestions!

like image 526
Coffeeman Avatar asked Aug 09 '15 17:08

Coffeeman


People also ask

How do you separate a parent from a child in CSS?

As a 1st thought, adding a class or ID to the child menu would do your job. you can use CSS :not when it comes to child ul or li . Also a child menu can be usually selected like ul li ul li when a parent can be selected like ul li .

How do you make a child div expand with their parents?

You can try adding a fixed height to the parent which might work or put enough content in the child to stretch it; that will work. Show activity on this post. You have margin-bottom set on both elements. With the child having a bottom margin, it will always be smaller by that amount.

How do I not affect my child CSS?

You cannot "disable" or "turnoff" inhertiance in CSS. The best you could do is "negate" it such as if parent has color: red; than child will also be red. So on child you can set color: black; Only some, not all, CSS properties are inherited.


2 Answers

Curious, just using layout_margin does not seem to work. However,

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:padding="10dp"
         android:clipToPadding="false">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="-10dp"
        android:layout_marginStart="-10dp"
        android:layout_marginEnd="-10dp"
        android:layout_marginBottom="-10dp" />
</FrameLayout>

seems to work (IntelliJ android preview).

Do not forget: android:clipToPadding="false" in the parent layout.

like image 195
Sascha Kolberg Avatar answered Oct 06 '22 06:10

Sascha Kolberg


Seems like things would be easier if you would just remove the android:padding="10dp" from your FrameLayout and in your "normal" fragments you add the 10dp padding, while in your "special" fragment you don't add any padding. Negative margins can be done, but in my opinion should only be used if there is no other way to do it.

like image 43
donfuxx Avatar answered Oct 06 '22 06:10

donfuxx