2015-03-31 150 views
6

我有以下佈局文件:如何刪除默認佈局的填充/保證金

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> 

和其他一些片段就像

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> 

在Lint中一切看起來都很好,但是當我在Nexus 7 5.0.2上執行我的應用程序時,用顯示的填充或邊距可能爲10像素。

這由箭頭示出的下列圖像enter image description here

如何強制佈局不添加這些填充/緣上?

編輯:我要補充我如何插入我的片段。

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(); 
    } 
} 

,我不使用任何夢詩任何地方...... THKS

+1

它不應該顯示任何填充或邊距。什麼容器,你實際上取代你的片段的佈局?並且請不要使用像素 - 這在Android上不是很好的做法。 – Darwind 2015-03-31 09:35:50

+0

您是否在使用res/values/dimens.xml中的任何內容 – Arlind 2015-03-31 09:38:43

+0

順便說一句:您錯過了底部邊距。並且不要使用'px'單位。 – 2015-03-31 09:38:46

回答

27

進入這個文件res/values/dimens.xml並更改值0dp就像下面的代碼。

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

+0

這就是我所做的THKS – 2ndGAB 2015-03-31 14:07:39

+0

哪裏的XML參考dimens.xml – 2016-06-16 17:18:05

+0

它引用它從main_activity。?。 xml是在打開一個新項目時默認創建的,但是它的問題是dimens.xml沒有被引用到任何地方,我只是瘋狂地猜測,顯然我知道它是正確的:) – Arlind 2016-06-17 07:34:55

1

我知道這已經回答了問題,但,我只碰到過這樣的問題,幫助了答案,但不完全,因爲有一個正確的填充。我發現,這是因爲我使用的主題中設置了填充。那些仍然看到填充可能會有所幫助。你需要做的就是刪除它。