2017-04-21 66 views
-1

我有一個ImageView在RelativeLayout中的5個按鈕,並給每個頂部的視圖留出一定的餘量。但是從頂端的保證金不符合我的條件。 我的代碼是:從頂部的邊距不與RelativeLayout一起工作?

<?xml version="1.0" encoding="utf-8"?> 
<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" > 

    <LinearLayout 
     android:id="@+id/header" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentTop="true"> 

     <fragment 
      android:name="motorpool.orbitsysindia.com.motorpool.model.splash.view.fragment.FragmentHeaderLineColor" 
      android:layout_width="match_parent" 
      android:tag="@string/fragment_header" 
      android:layout_height="wrap_content"> 
     </fragment> 

    </LinearLayout> 


     <RelativeLayout 
      android:layout_width="match_parent" 
      android:layout_height="match_parent" 
      android:layout_marginTop="20dp" 
      android:layout_alignParentTop="true" 
      android:layout_below="@+id/header"> 

      <ImageView 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:id="@+id/imageCar" 
       android:layout_centerHorizontal="true" 
       android:src="@drawable/mu7"/> 

       <motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold 
        android:id="@+id/btnJointInsp" 
        style="@style/ButtonTextMenu" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/imageCar" 
        android:layout_marginTop="20dp" 
        android:text="@string/menuJointInsp" /> 

       <motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold 
        android:id="@+id/btnVehRec" 
        style="@style/ButtonTextMenu" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/btnJointInsp" 
        android:layout_marginTop="200dp" 
        android:text="@string/menuVehicleRec" /> 

       <motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold 
        android:id="@+id/btnRecIns" 
        style="@style/ButtonTextMenu" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/btnVehRec" 
        android:layout_marginTop="20dp" 
        android:text="@string/menuRecIns" /> 

       <motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold 
        android:id="@+id/btnPdi" 
        style="@style/ButtonTextMenu" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/btnRecIns" 
        android:layout_marginTop="20dp" 
        android:text="@string/menuPDI" /> 

       <motorpool.orbitsysindia.com.motorpool.util.custom.ButtonBold 
        android:id="@+id/btnLocation" 
        style="@style/ButtonTextMenu" 
        android:layout_width="match_parent" 
        android:layout_height="wrap_content" 
        android:layout_below="@+id/btnPdi" 
        android:background="@drawable/vehicle_list" 
        android:text="@string/menuLocation" /> 

     </RelativeLayout> 
    <RelativeLayout 
     android:id="@+id/footer" 
     android:layout_width="match_parent" 
     android:layout_height="wrap_content" 
     android:layout_alignParentBottom="true" 
     android:background="@color/white" 
     android:gravity="center"> 

     <fragment 
      android:name="motorpool.orbitsysindia.com.motorpool.model.splash.view.fragment.FragmentFooter" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      tools:layout="@layout/fragment_footer" /> 

    </RelativeLayout> 

</RelativeLayout> 

任何形式的幫助是由我讚賞:

回答

0
 <RelativeLayout 
     android:layout_width="match_parent" 
     android:layout_height="match_parent" 
     android:layout_marginTop="20dp" 
     android:layout_alignParentTop="true" 
     android:layout_below="@+id/header"> 

請從這個相對佈局刪除android:layout_alignParentTop="true"

+0

沒有工作..? – Champandorid

1

問題android:layout_alignParentTop

如果真正的,使頂部edg此視圖的e與父親的頂邊相匹配。容納頂部邊緣。

您應該刪除android:layout_alignParentTop="true"財產。

編輯

這真的只是一個RelativeLayout的臭蟲,所以你可以嘗試 包裹RelativeLayout的一個的LinearLayout內並設置保證金 那裏。

Source

+0

這樣做但不起作用。 – Champandorid

+0

@Champandorid http://stackoverflow.com/a/15360874/3395198 –

+0

使其match_parent,但沒有奏效。我不知道爲什麼... – Champandorid