Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
329 views
in Technique[技术] by (71.8m points)

android - 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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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>


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...