2017-04-21 65 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