2014-07-16 48 views
0

我有一個相對佈局,其中包含其他兩個相對佈局,每個都有圖像,並且我已將每個圖像作爲相對佈局的背景,但仍然可以看到圖像(佈局)和整體之間的空間父母的佈局..所以我怎麼能刪除這個空間? 這是我的XML代碼:如何刪除佈局和背景之間的空間?

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

     <RelativeLayout 
      android:id="@+id/relative1" 
      android:layout_width="match_parent" 
      android:layout_height="150sp" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/upper" > 
    </RelativeLayout> 

      <RelativeLayout 
       android:id="@+id/relative2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentRight="true" 
       android:layout_below="@+id/relative1" 
       android:background="@drawable/down" > 

    <ListView 
     android:id="@+id/listView1" 
     android:layout_width="wrap_content" 
     android:layout_height="280dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" > 

    </ListView>  
    </RelativeLayout> 
    </RelativeLayout> 

我怎樣才能解決這個問題呢?

+0

真的嗎?你有這種懷疑嗎? – iZBasit

回答

0

在你的頂層佈局取出填充

+0

你的解決方案爲我工作 – sereen

0

刪除主RelativeLayout所有填充屬性。

嘗試......

<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" 
    tools:context=".MainActivity" > 

     <RelativeLayout 
      android:id="@+id/relative1" 
      android:layout_width="match_parent" 
      android:layout_height="150sp" 
      android:layout_alignParentRight="true" 
      android:layout_alignParentTop="true" 
      android:layout_alignParentLeft="true" 
      android:background="@drawable/upper" > 
     </RelativeLayout> 

     <RelativeLayout 
       android:id="@+id/relative2" 
       android:layout_width="match_parent" 
       android:layout_height="wrap_content" 
       android:layout_alignParentBottom="true" 
       android:layout_alignParentLeft="true" 
       android:layout_alignParentRight="true" 
       android:layout_below="@+id/relative1" 
       android:background="@drawable/down" > 

     <ListView 
     android:id="@+id/listView1" 
     android:layout_width="wrap_content" 
     android:layout_height="280dp" 
     android:layout_alignParentLeft="true" 
     android:layout_alignParentTop="true" > 


     </ListView>  
    </RelativeLayout> 
</RelativeLayout> 

這可能會幫助你..

0

你相對佈局定義爲:

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

在這裏,您已經定義了它應該始終對保證金擁有以下屬性的各方:

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

只需刪除它們,你應該沒問題。

你想要什麼:

<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" 
     tools:context=".MainActivity" >