8

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

fralbo
  • 2,534
  • 4
  • 41
  • 73
  • 1
    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 09:35
  • Are you using anything from res/values/dimens.xml – Arlind Hajredinaj Mar 31 '15 at 09:38
  • BTW: you missed bottom margin. and do not use `px` units. – Marcin Orlowski Mar 31 '15 at 09:38
  • @Darwin, I just wanted to verify if I can override default margin/padding definitions but obviously, it doesn't change anything. – fralbo Mar 31 '15 at 09:49
  • But there isn't any "default padding/margin" unless you set something yourself :-) EDIT: I see you added the `onCreate` method. Show us the XML for `R.id.frame_container` please... – Darwind Mar 31 '15 at 09:50
  • @Arlind: Thks I effectively have activity_horizontal_margin and activity_vertical_margin set to 16dp in dimens.xml – fralbo Mar 31 '15 at 09:59
  • @caBBAlainB Change that to 0dp and that should do the trick, but I really dont know where you are using activity_horizontal_margin and activity_vertical_margin ? – Arlind Hajredinaj Mar 31 '15 at 11:51
  • 1
    @Arlind now eclipse creates a layout with the following default attributes: – fralbo Mar 31 '15 at 13:17
  • Yes exactly but where in your code are you using android:paddingLeft="@dimen/activity_horizontal_margin" – Arlind Hajredinaj Mar 31 '15 at 13:40

2 Answers2

31

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>

Arlind Hajredinaj
  • 8,380
  • 3
  • 30
  • 45
1

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.

Sely Lychee
  • 312
  • 1
  • 9