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
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
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.
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.
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.
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.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With