I have three radiobuttons and I want to evenly space them across the screen. When I use android:layout_weight="1", the buttons are stretched out across the screen. So how would I have the same amount of space in between each of them that also scales on different screen sizes?
<RadioGroup
android:id="#+id/auton_bar"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:paddingLeft="10dp"
android:layout_below="#id/clear_fields"
>
<RadioButton
android:id="#+id/auton_radio_1"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/auton_col"
android:layout_weight="1"
/>
<!-- android:layout_marginRight="380dp" -->
<RadioButton
android:id="#+id/auton_radio_2"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/auton_col"
android:layout_weight="1"
/>
<RadioButton
android:id="#+id/auton_radio_3"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:background="#drawable/auton_col"
android:layout_weight="1"
/>
</RadioGroup>
If you want them to share screen width equally you need to set android:layout_width="match_parent" on each View. Your xml would become:
<RadioGroup
android:id="#+id/auton_bar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#id/clear_fields"
android:orientation="horizontal"
android:paddingLeft="10dp" >
<RadioButton
android:id="#+id/auton_radio_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/auton_col" />
<!-- android:layout_marginRight="380dp" -->
<RadioButton
android:id="#+id/auton_radio_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/auton_col" />
<RadioButton
android:id="#+id/auton_radio_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:background="#drawable/auton_col" />
</RadioGroup>
To elaborate, layout_weight can be used in two ways.
If you have multiple views in a vertical linear layout and you want the last one to take up all the remaining space, you can set their heights to wrap_content and give the last view a weight of 1.
If you want all views to share the available space, set all width/heights to 0dp or match_parent and give each view the same weight value. They will share the space equally.
To have your background drawable scale, make a new xml that goes in your drawable/ folder that looks like this
<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
android:gravity="center"
android:src="#drawable/auton_col" />
Name it whatever you like (e.g. auton_col_scale.xml) and reference that drawable as your background.
I noticed that using layout weights for the RadioButton's caused them to be aligned off-center, eventhough they definitely each shared 50% of the screen (they were left-aligned). Setting a gravity for each RadioButton caused only the text to be centered /facepalm
The XML below shows how to horizontally align two radiobuttons (could be any views) and center them:
<RadioGroup
android:id="#+id/radiogroup"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<RadioButton
android:id="#+id/radioyes"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/yes"
android:checked="false"/>
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
<RadioButton
android:id="#+id/radiono"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/no"
android:checked="false"/>
<Space
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</RadioGroup>
set width to match parent of each layout and then add weight jsut like linear layout.
<RadioGroup
android:id="#+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/bigMarginStart"
android:layout_marginTop="#dimen/smallMarginTop"
android:layout_marginEnd="#dimen/baseMarginEnd"
android:orientation="horizontal"
android:weightSum="3"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="#+id/all_"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/smallMarginTop"
android:layout_weight="1"
android:background="#drawable/radio_flat_selector"
android:button="#android:color/transparent"
android:checked="true"
android:gravity="center"
android:paddingLeft="#dimen/bigPaddingStart"
android:paddingTop="#dimen/smallPaddingTop"
android:paddingRight="#dimen/bigPaddingStart"
android:paddingBottom="#dimen/smallPaddingBottom"
android:text="All" />
<RadioButton
android:id="#+id/future_"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginStart="#dimen/smallMarginStart"
android:layout_marginTop="#dimen/smallMarginTop"
android:layout_marginEnd="#dimen/smallMarginEnd"
android:layout_weight="1"
android:background="#drawable/radio_flat_selector"
android:button="#android:color/transparent"
android:gravity="center"
android:paddingLeft="#dimen/bigPaddingStart"
android:paddingTop="#dimen/smallPaddingTop"
android:paddingRight="#dimen/bigPaddingStart"
android:paddingBottom="#dimen/smallPaddingBottom"
android:text="Future" />
<RadioButton
android:id="#+id/direct_"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/smallMarginTop"
android:layout_weight="1"
android:background="#drawable/radio_flat_selector"
android:button="#android:color/transparent"
android:gravity="center"
android:paddingLeft="#dimen/bigPaddingStart"
android:paddingTop="#dimen/smallPaddingTop"
android:paddingRight="#dimen/bigPaddingStart"
android:paddingBottom="#dimen/smallPaddingBottom"
android:text="Direct" />
</RadioGroup>
Related
I have two Buttons called btnBeginner and btnAdvanced.
I have divided these two Buttons equally by using the layout_weight property. But the layout_weight is bad for performance.
Because of that, I would like to change my existing code - which is shown below.
<LinearLayout
android:id="#+id/lLayoutBeginAdv"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/btnBeginner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#color/color_exam_btn_hlight"
android:text="beginner"
android:textAllCaps="false"
android:textColor="#color/white"
android:textStyle="normal" />
<Button
android:id="#+id/btnAdvanced"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_weight=".5"
android:background="#color/color_exam_btn_normal"
android:text="advanced"
android:textAllCaps="false"
android:textColor="#color/white"
android:textStyle="normal" />
</LinearLayout>
Please help me to do the same without using the layout_weight property.
EDIT : PercentRelativeLayout was deprecated in API level 26.1.0.
consider using ConstraintLayout and associated layouts instead.
Nested weights are bad for performance because :
Layout weights require a widget to be measured twice. When a
LinearLayout with non-zero weights is nested inside another
LinearLayout with non-zero weights, then the number of measurements
increase exponentially.
So in your case, weight will not create the performance problem. But still if you want to divide the layout into two equal parts without using weight, you can use PercentRelativeLayout
Sample :
android.support.percent.PercentRelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent">
<Button
android:id="#+id/btnBeginner"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/color_exam_btn_hlight"
android:text="beginner"
android:textAllCaps="false"
android:textColor="#color/white"
android:textStyle="normal"
app:layout_heightPercent="50%"
app:layout_widthPercent="50%"
/>
<Button
android:id="#+id/btnAdvanced"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="#color/color_exam_btn_normal"
android:text="advanced"
android:textAllCaps="false"
android:textColor="#color/white"
android:textStyle="normal"
app:layout_heightPercent="50%"
app:layout_widthPercent="50%"/>
</android.support.percent.PercentRelativeLayout>
Visit this Github repo for more information
I'd place a dummy View in the center of a RelativeLayout.
Then set a Button to the right of it and another one to the left of it.
Something like so
<RelativeLayout>
<!-- Dummy in the center -->
<View
android:id="#+id/dummy"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
/>
<!-- Left Button -->
<Button
android:id="#+id/button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:toLeftOf="#id/dummy"
android:text="New Button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
/>
<!-- Right Button -->
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:toRightOf="#id/dummy"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
/>
</RelativeLayout>
You should set layout_width = "0dp" for all the buttons in Linear Layout.
As layout_weight, superseding layout_width. So essentially the layout_width is getting ignored.
So basically you code should be like :
<LinearLayout
android:id="#+id/lLayoutBeginAdv"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:weightSum="2">
<Button
android:id="#+id/btnBeginner"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
...../>
<Button
android:id="#+id/btnAdvanced"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
..... />
</LinearLayout>
For more reference you should this link :
layout_width and layout_weight - performance
If you don't want use layout_weight use Relative Layout`
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New Button"
android:id="#+id/button2"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
</RelativeLayout>`
If you are looking out to divide two buttons in single row using constraint layout then below is the example for you.
<?xml version="1.0" encoding="utf-8"?>
<android.support.constraint.ConstraintLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.com.schooldemo.example.MainActivity">
<Button
android:id="#+id/buttonA"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="A"
app:layout_constraintEnd_toStartOf="#+id/buttonD"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toStartOf="parent" />
<Button
android:id="#+id/buttonD"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="D"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_weight="1"
app:layout_constraintStart_toEndOf="#+id/buttonA" />
</android.support.constraint.ConstraintLayout>
I have 2 buttons nested inside a Horizontal LinearLayout, and I want to align them both to the bottom of the screen. I've set the LinearLayout's weightsum property to 1 & the 2 buttons' layoutweight property also to 1 & I get this result :
I get this weird space around the buttons and I want to eliminate it. How to ?
Here is the XML code:
<LinearLayout
android:id="#+id/hourlyDailyLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:orientation="horizontal">
<Button
android:id="#+id/hourlyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/hourly"
android:textColor="#ffffffff"
/>
<Button
android:id="#+id/dailyButton"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/daily"
android:textColor="#ffffffff"
/>
</LinearLayout>
Buttons have padding by default. They way to combat that is to set negative margins
<Button
android:id="#+id/dailyButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/daily"
android:textColor="#ffffffff"
android:layout_marginBottom="-5dp"
/>
<Button
android:id="#+id/hourlyButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/hourly"
android:textColor="#ffffffff"
/>
<Button
android:id="#+id/dailyButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="#string/daily"
android:textColor="#ffffffff"
/>
set the width to 0dp
I'm attempting to resize buttons on rotate to expand proportionately. Right now, they are a fix length, but I'm unsure of an alternative method to get the buttons to resize (setting the weight doesn't seem to help). I want the buttons to essentially fill the length of the screen both vertically and horizontally. Please let me know if you need more information.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="5dp"
android:layout_gravity="center_vertical" >
<Button
android:id="#+id/mainCommentBtn"
android:layout_width="119dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_weight="1"
android:text="#string/commentBtn" />
<Button
android:id="#+id/mainProfileBtn"
android:layout_width="119dp"
android:layout_height="wrap_content"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_weight="1"
android:layout_centerInParent="true"
android:text="#string/profileBtn" />
<Button
android:id="#+id/mainDetailBtn"
android:layout_width="119dp"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:layout_weight="1"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="#string/shareBtn" />
</LinearLayout>
Replace your resource with this. Copy the edited changes
Notice how there width is 0dp because they are using weight.
Using Weight:
1. In order to use weight you need to set the weightSum in the parent.
2. Make sure the width or height is set to 0 according to how you are using weight.
(for instance since we are going with horizontal orientation we want to use "0dp" width. This allows weight to control the width of the object.
3. Lastly make sure the weight of all the objects add up to the weightSum.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginTop="5dp"
android:orientation="horizontal"
android:weightSum="3" >
<Button
android:id="#+id/mainCommentBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_weight="1"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="#string/commentBtn" />
<Button
android:id="#+id/mainProfileBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:layout_weight="1"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="#string/profileBtn" />
<Button
android:id="#+id/mainDetailBtn"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_weight="1"
android:clickable="true"
android:focusable="false"
android:focusableInTouchMode="false"
android:text="#string/shareBtn" />
</LinearLayout>
You need to specify an orientation for the LinearLayout.
I guess you want to use android:orientation="horizontal".
Then, in order to make android:weight work, you'd need to specify the width of every button as 0px by using android:layout_width="0px" for every button.
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Button" />
These xml properties size the button to fill the screen both vertically and horizontally.
You can create the layout with the help of layout weight so that it will automatically fill the screen in landscape mode also as below:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="3" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 1"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 2"
android:layout_weight="1" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Button 3"
android:layout_weight="1" />
</LinearLayout>
I've created a custom listview. All works fine though I struggle with the layout of the listitem.
The idea is to have a textview which can have a variable length (multilines is possible) and two buttons next to the textview all on one line.
This is what I have:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_weight=".80" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A"
android:layout_weight=".10"
android:layout_toRightOf="#id/textView1" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B"
android:layout_weight=".10"
android:layout_toRightOf="#id/button1" />
This works fine though my problem is that the textview fills out the parent and pushes the buttons of the screen. (when I have a short text the buttons are vissible)
So basically, what I need is a 80% wide textview aligned to the left and two 10% wide buttons aligned to the right. Can anyone guide me in the right direction?
Thanks
You can't use layout_weight with RelativeLayout. Try this:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView1"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:textSize="16sp"
android:layout_weight="1" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="A" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="B" />
</LinearLayout>
Change to LinearLayout. You cannot use layout_weight with RelativeLayout.
Good Luck
This is my custom dialog, there are some textboxs and two buttons.
I'm using a RelativeLayout on it.
I'd like the dialog size to match the content, not all that blank space under there.
I don't want to use explicit pixel heights (it's not good practice).
Another thing, there's a way to have some space between every view?
This is my XML
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<TextView
android:id="#+id/txt_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textSize="8pt"
android:textStyle="italic" />
<TextView
android:id="#+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_below="#+id/txt_desc"
android:textSize="8pt" />
<TextView
android:id="#+id/txt_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_below="#+id/txt_date"
android:textSize="8pt" />
<Button
android:id="#+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/txt_place"
android:layout_toRightOf="#+id/view"
android:text="#string/btn_close" />
<View
android:id="#+id/view"
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_centerHorizontal="true" />
<Button
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/txt_place"
android:layout_toLeftOf="#+id/view"
android:drawableLeft="#android:drawable/ic_menu_edit"
android:text="#string/btn_edit" />
</RelativeLayout>
First question
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
Second question
Plus use android:marginTop="5dp" if you want to separate a View from Top for 5 dp.
marginLeft|Right|Bottom are also available.
<TextView
android:id="#+id/txt_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:layout_marginTop="5dp" <-----------------
android:layout_below="#+id/txt_date"
android:textSize="8pt" />
By the way, if I were you, I'd nest some layouts to make order. You can have a general Relative Layout, then 2 linear layouts: one horizontal for TextViews and one vertical for Buttons. You can definely play with your editor and try to make the best appearance for your dialog.
EDIT
Try this one:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#0000"
android:orientation="vertical"
android:paddingBottom="50dp" >
<LinearLayout
android:orientation="vertical"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:id="#+id/txt_desc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="prova"
android:textSize="8pt"
android:textStyle="italic" />
<TextView
android:id="#+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="prova"
android:textSize="8pt" />
<TextView
android:id="#+id/txt_place"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:text="prova"
android:textSize="8pt" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<Button
android:id="#+id/btn_edit"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:drawableLeft="#android:drawable/ic_menu_edit"
android:text="btn_edit" />
<Button
android:id="#+id/btn_close"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="btn_close" />
<View
android:id="#+id/view"
android:layout_width="0dp"
android:layout_height="1dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I've hard-coded the texts. The main idea is to use a big container layout in background, which is trasparent (background=#0000) and in top of that a layout in wrap_content containing your Views.
If this solution doesn't resolve your problem, I think you could edit height directly in your code. Try to relate to this question
Set your relative layout's height to wrap_content.
For example:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<!-- More XML -->
</RelativeLayout>
Also be aware that fill_parent is deprecated for widths and heights.
You can add either margin (extra space outside a view) or padding (extra space inside a view) with android:layout_margin or android:padding respectively. There are also variants such as layout_marginTop that only apply to a specific side of the view.