Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove default layout's padding/margin

I have the following layout files:

activity_main.xml

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:map="http://schemas.android.com/apk/res-auto"
    android:id="@+id/frame_container"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:layout_marginLeft="0px"
    android:layout_marginRight="0px"
    android:layout_marginTop="0px"
    android:padding="0dp"
    >
    ...
</FrameLayout>

And some other fragments like

fragment_init.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/fragmentInit"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:padding="0dp"
    android:layout_marginTop="0px"
    android:layout_marginLeft="0px"
    android:layout_marginRight="0px"
    android:background="#549F07"
    >

    <TextView
        ... 
    >
    ...
</RelativeLayout>

Everything looks fine in Lint, but when I execute my application on my Nexus 7 5.0.2, every container is displayed with a padding or margin of maybe 10 px.

This is illustrated by the arrows on the following image enter image description here

How to force the layouts to not add these padding/margin?

Edit: I should add how I insert my fragment.

Activiy

 public class MainActivity extends Activity {
    @Override
    protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        FragmentTransaction fragmentTransaction = getFragmentManager().beginTransaction();
        fragmentTransaction.setTransition(FragmentTransaction.TRANSIT_FRAGMENT_OPEN);
        fragmentTransaction.replace(R.id.frame_container, new Fragment_init(), "Fragment_init").commit();
    }
}

and I don't use any dimens anywhere... Thks

like image 819
fralbo Avatar asked Mar 31 '15 09:03

fralbo


People also ask

How to solve the padding problem in my layout?

You can solve this problem by giving negative padding or margin to your layout but that is not accurate solution. So the best solution is to set Inset from all corners to 0dp.

Does fragment layout show padding or margin?

It shouldn't show any padding or margin. What container are you actually replacing with your fragment's layout? And please refrain from using pixels - it's not good practice on Android. – Darwind Mar 31 '15 at 9:35 Are you using anything from res/values/dimens.xml – Arlind Mar 31 '15 at 9:38 BTW: you missed bottom margin. and do not use pxunits.

How to fix toolbar layout with too much padding?

You can solve this problem by giving negative padding or margin to your layout but that is not accurate solution. So the best solution is to set Inset from all corners to 0dp. Below is example to set 0dp inset from all corners in toolbar layout.

How do I remove padding from the Mui grid?

Here are two steps to completely remove padding from the MUI Grid: The first step should be enough, but if you still have padding then confirm the second step is complete. You should have a grid like the below after completing these steps: The code for styling the root of the Grid is almost identical between makeStyles and the sx prop.


2 Answers

Go into this file res/values/dimens.xml and change the values to 0dp just like in the code below.

<dimen name="activity_horizontal_margin">0dp</dimen>
<dimen name="activity_vertical_margin">0dp</dimen>

like image 68
Arlind Avatar answered Oct 11 '22 16:10

Arlind


I know this is already answered question but, i just come across such an issue, the answer helped but not completely, as there was a right padding. I found out that, it is because of the padding set in the Theme i used. It might be helpful for those still see the padding. All you need to do is remove it.

like image 28
Sely Lychee Avatar answered Oct 11 '22 17:10

Sely Lychee