Reputation: 1204
I have 5 button with an ImageView inside RelativeLayout and giving some margin to each of view from the top. But margin from top does not working in my condition. My code is :
<?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>
Any kind of help is Appreciated by me:
Upvotes: 0
Views: 1344
Reputation: 488
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="20dp"
android:layout_alignParentTop="true"
android:layout_below="@+id/header">
Please remove android:layout_alignParentTop="true"
from this relative layout
Upvotes: 1
Reputation: 75788
Problem android:layout_alignParentTop
If true, makes the top edge of this view match the top edge of the parent. Accommodates top margin.
You should remove android:layout_alignParentTop="true"
property .
EDIT
It is really just a bug of the RelativeLayout, so you could try to wrap the RelativeLayout inside of a LinearLayout and set the margin there.
Source .
Upvotes: 1