2014-07-22 22 views
0

我使用這個XML文件:Android的屏幕Marign

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context=".MainActivity" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_marginTop="0px" 
    android:src="@drawable/up" /> 


    <ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    android:layout_below="@+id/imageView1" 

    android:layout_marginTop="0px" 
    android:src="@drawable/back" /> 

我想設置imageView1到屏幕的頂部,但ImageView的具有屏幕和ImageView的不match_parent或FILL_PARENT的一點空間頂部和我想的ImageView低於imageView1,但比imageView1有一點空間。

該怎麼解決呢?

+1

發佈正在發生的事情的圖像和你想要的線框圖 – Ravi

+1

兩個選項(我認爲)。從RelativeLayout中移除所有'android:padding *'值。或者,在'ImageView'上使用'android:layout_marginTop'的負值 – Tigger

+0

@Tigger刪除所有填充並解決它,但imageView1未設置爲match_parent – user3851833

回答

0

所有你需要做的就是REMOVE PADDING從父layout標籤

試試這個代碼....

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" <!--Removed unnecessary padding --> 
    tools:context=".MainActivity" > 

<ImageView 
    android:id="@+id/imageView1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" <!--Moves To Top of The Screen --> 
    android:src="@drawable/up" /> 


    <ImageView 
    android:id="@+id/imageView2" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_below="@+id/imageView1" <!--Moves bellow of imageview1 --> 
    android:src="@drawable/back" /> 

</RelativeLayout> 
+0

謝謝,它解決了,但imageView1沒有設置爲匹配的寬度! – user3851833

+0

最新的問題是什麼? –

0
**Remove padding**  
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="match_parent" 
    android:layout_height="match_parent" 
    **//android:paddingBottom="@dimen/activity_vertical_margin" 
    //android:paddingLeft="@dimen/activity_horizontal_margin" 
    //android:paddingRight="@dimen/activity_horizontal_margin" 
    //android:paddingTop="@dimen/activity_vertical_margin"** 
    tools:context=".MainActivity" > 

    <ImageView 
     android:id="@+id/imageView1" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_marginTop="0px" 
     android:src="@drawable/up" /> 


     <ImageView 
     android:id="@+id/imageView2" 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_below="@+id/imageView1" 

     android:layout_marginTop="0px" 
     android:src="@drawable/back" /> 
0

您父母的RelativeLayout刪除此行。

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin"