This is my xml. I need to place my icon to extreme right. But it's not moving to extreme right. "tri_logo" I have given gravity as right. But still not moving to right.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toplayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical" >
<LinearLayout
android:id="#+id/lout_profile_header"
android:layout_width="match_parent"
android:layout_height="#dimen/top_view_height"
android:clickable="true"
android:gravity="center"
android:orientation="horizontal">
<com.test.customviews.CircleImageView
android:id="#+id/imgTopProfile"
android:layout_width="#dimen/profilie_icon_size"
android:layout_height="#dimen/profilie_icon_size"
android:layout_margin="#dimen/hdr_img_padding"
android:src="#mipmap/ic_profile" />
<TextView
android:id="#+id/textTopProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="#dimen/hdr_name_padding" />
<ImageView
android:id="#+id/tri_logo"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:src="#drawable/tri_logo"/>
</LinearLayout>
</LinearLayout>
ImageView tri_logo is not moving to right.
Try this
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toplayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical">
<LinearLayout
android:id="#+id/lout_profile_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:clickable="true"
android:weightSum="3"
android:layout_gravity="right"
android:orientation="horizontal">
<com.test.customviews.CircleImageView
android:id="#+id/imgTopProfile"
android:layout_weight="1"
android:layout_width="#dimen/profilie_icon_size"
android:layout_height="#dimen/profilie_icon_size"
android:layout_margin="#dimen/hdr_img_padding"
android:src="#mipmap/ic_profile" />
<TextView
android:layout_weight="1"
android:id="#+id/textTopProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
/>
<ImageView
android:layout_weight="1"
android:id="#+id/tri_logo"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:src="#drawable/voyage"/>
</LinearLayout>
</LinearLayout>
You could use RelativeLayout and then use layout_alignParentEnd=true, if you want to stick on to LinearLayout try above one
Wrap up your ImageView in a RelativeLayout with match_parent width and use
android:layout_alignParentRight="true"
like this:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/tri_logo"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:src="#drawable/tri_logo"/>
</RelativeLayout>
Use the tools a LinearLayout provides. Give weight to your child views and change the parent layout's gravity to right
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toplayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lout_profile_header"
android:layout_width="match_parent"
android:layout_height="100dp"
android:clickable="true"
android:gravity="center">
<com.test.customviews.CircleImageView
android:id="#+id/imgTopProfile"
android:layout_width="#dimen/profilie_icon_size"
android:layout_height="#dimen/profilie_icon_size"
android:layout_margin="#dimen/hdr_img_padding"
android:src="#mipmap/ic_profile" />
<TextView
android:id="#+id/textTopProfile"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_marginLeft="100dp" />
<ImageView
android:layout_alignParentRight="true"
android:id="#+id/tri_logo"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_gravity="right"
android:src="#drawable/tri_logo"/>
</RelativeLayout>
</LinearLayout>
Use RelatiVeLayout as immediate parent .
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/toplayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:clickable="true"
android:orientation="vertical" >
<RelativeLayout
android:id="#+id/lout_profile_header"
android:layout_width="match_parent"
android:layout_height="#dimen/top_view_height"
android:clickable="true"
>
<com.test.customviews.CircleImageView
android:id="#+id/imgTopProfile"
android:layout_width="#dimen/profilie_icon_size"
android:layout_height="#dimen/profilie_icon_size"
android:layout_centerVertical="true"
android:layout_margin="#dimen/hdr_img_padding"
android:src="#mipmap/ic_profile" />
<TextView
android:id="#+id/textTopProfile"
android:layout_width="match_parent"
android:layout_centerVertical="true"
android:layout_height="wrap_content"
android:gravity="center"
android:layout_toLeftOf="#+id/tri_logo"
android:layout_toRightOf="#+id/imgTopProfile"
android:layout_marginLeft="#dimen/hdr_name_padding" />
<ImageView
android:id="#+id/tri_logo"
android:layout_width="30dp"
android:layout_centerVertical="true"
android:layout_height="30dp"
android:layout_alignParentRight="true"
android:src="#drawable/tri_logo"/>
</RelativeLayout>
</LinearLayout>
Related
I'm trying to position the blue icon precisely in the center of the card, but for some reason the icon goes up to the top of the card.
Can someone tell me what's wrong?
Thanks,
Here's a screenshot of my problem:
<GridView
android:id="#+id/documents_grid"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="10dp"
android:columnWidth="#dimen/document_grid_item_width"
android:gravity="center"
android:horizontalSpacing="0dp"
android:numColumns="auto_fit"
android:stretchMode="spacingWidthUniform"
android:verticalSpacing="48dp" />
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:background="#drawable/document_grid_item_bg">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
app:srcCompat="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
app:srcCompat="#drawable/draft_icon" />
</RelativeLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Date" />
</RelativeLayout>
I assume that in gridview item your parent is LinearLayout which can't be seen from your code snippet. If that's the case, in FrameLayout properties set the height to wrap_content
<FrameLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.9"
android:focusable="true"
android:foreground="?android:selectableItemBackground"
android:background="#drawable/document_grid_item_bg">
Given code snippet is working fine with LinearLayout as parent.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="vertical"
android:layout_height="wrap_content">
<FrameLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:focusable="true"
android:background="#color/colorGreen"
android:foreground="?android:selectableItemBackground">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
app:srcCompat="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
app:srcCompat="#drawable/draft_icon"
android:layout_centerInParent="true" />
</RelativeLayout>
</FrameLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="Date" />
</RelativeLayout>
</LinearLayout>
1. Remove FrameLayout and add its attributes to child RelativeLayout.
2. Use attribute android:src instead of app:srcCompat to set image on ImageView.
Try this:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.9"
android:background="#fff">
<ImageView
android:id="#+id/draft_more_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:layout_marginTop="5dp"
android:layout_marginRight="5dp"
android:src="#drawable/ic_more" />
<ImageView
android:id="#+id/imageView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:src="#drawable/draft_icon" />
</RelativeLayout>
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_margin="5dp"
android:layout_weight="0.1">
<TextView
android:id="#+id/draft_date_tv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerInParent="true"
android:text="16 May 2017" />
</RelativeLayout>
</LinearLayout>
FYI, If you are using CardView as a container, then just put below LinearLayout inside your CardView.
OUTPUT:
i have weird problem, in my listview row i have textview and imageview, with weights 2 and 1 respectively, but if the textview text is single line or has less characters the imageview is not aligned to the right, please find my listview row layout code.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3">
<TextView
android:id="#+id/cat_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:text="fruits"
android:textColor="#80000000"
android:textSize="25dp" />
<ImageView
android:id="#+id/cat_pic"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="1"
android:src="#drawable/image1" />
</LinearLayout>
Please find the image below
I think is not appropriate to use weight in textview and edittext, I modified your code like this below:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="3">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2"
android:gravity="center">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="fruits"
android:textColor="#80000000"
android:textSize="25dp"/>
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center">
<ImageView
android:id="#+id/cat_pic"
android:layout_width="wrap_content"
android:layout_height="100dp"
android:layout_weight="1"
android:src="#drawable/image1" />
</LinearLayout>
Try this.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="150dp"
android:gravity="center"
android:orientation="horizontal"
android:weightSum="6">
<TextView
android:id="#+id/cat_name"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:layout_gravity="left"
android:text="Vegetables and Fruits"
android:textColor="#80000000"
android:textSize="25dp" />
<ImageView
android:id="#+id/cat_pic"
android:layout_width="0dp"
android:layout_gravity="right"
android:layout_height="100dp"
android:layout_weight="2"
android:src="#drawable/guest_user_button_pressed" />
</LinearLayout>
To get view like this image just remove android:gravity="center"
But i suggest you create xml file like this:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/cat_name"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_toLeftOf="#+id/cat_pic"
android:text="abcdefghijklmnopqrstuvwxvzabcdefghijk"
android:textColor="#80000000"
android:textSize="25dp" />
<ImageView
android:id="#+id/cat_pic"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:scaleType="centerCrop"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
I have two image in layout .I want to show second image in bottom edge curve of first image .Can anybody tell how to do like overlay image
Thanks
Use FrameLayout :
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imgFirst"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"/>
<ImageView
android:id="#+id/imgSecond"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="bottom|center"
android:src="#drawable/ic_launcher"/>
</FrameLayout>
Use a RelativeLayout, simple put the second ImageView below the first ImageView. Then what you have to do is to set the marginTop attribute of the second image to a negative value, and this value is the overlaying size, like this android:layout_marginTop="-1dp".
A sample code right below:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent"
>
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/firstImage"
android:src="#drawable/myimage1"
/>
<ImageView
android:layout_width="wrap_content"
android:layout_marginTop="-1dp"
android:layout_height="wrap_content"
android:id="#+id/secondImage"
android:layout_below="#+id/firstImage"
android:src="#drawable/myimage2"
/>
</RelativeLayout>
You can do it without Frames, only using RelativeLayout, if you make use of the alignParentalXXX tags as in the following example
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout 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"
android:background="#E4E3CE"
android:orientation="vertical">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="75">
<ImageView
android:id="#+id/backgroundImageView"
android:layout_width="match_parent"
android:layout_height="300dp"
android:layout_alignParentTop="true"
android:layout_margin="5dp"
android:background="#ffffff" />
<ImageView
android:id="#+id/imageView"
android:layout_width="66dp"
android:layout_height="66dp"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="40dp"
android:layout_marginTop="20dp"
android:background="#40000000"
android:gravity="center_vertical"
android:paddingHorizontal="3dp"
android:paddingVertical="1dp"
android:text="Header Text"
android:textColor="#ffffff"
android:textSize="16dp" />
</RelativeLayout>
</LinearLayout>
You can see how this layout looks like in the following image:
Use Frame Layout like sample below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/ll_home_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:clickable="true"
android:focusable="true"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:background="#android:color/black"
android:gravity="center_vertical"
android:orientation="horizontal" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="35dp"
android:layout_height="35dp"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/ic_drawer"
android:src="#drawable/logo" />
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="14dp"
android:src="#drawable/menu" />
<ImageView
android:id="#+id/ic_drawer"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignTop="#+id/textView1_detail"
android:layout_marginLeft="4dp"
android:layout_marginRight="4dp"
android:src="#drawable/ic_drawer" />
<TextView
android:id="#+id/textView1_detail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="15dp"
android:layout_toRightOf="#+id/imageView1"
android:text="Reports"
android:textColor="#android:color/white"
android:textSize="18sp" />
</RelativeLayout>
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="#+id/overlay_favorite"
android:layout_width="215dp"
android:layout_height="134dp"
android:layout_gravity="right"
android:background="#drawable/overlay_favorite"
android:visibility="gone" />
</FrameLayout>
</LinearLayout>
In my layout i want to display two imagebuttons in the center and a my amountmeter below it on the bottom, all centered vertically, i have tried many ways but cant seem to find that perfect layout. all the component align vertically and center but it makes my amountmeter small and not full width of the screen.
How it should be
how it is now
updated code
current layout:
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_cart" />
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_sell" />
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center|bottom"
android:padding="4dp" />
COPY PASTE BELOW CODE
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/purchase"
android:layout_centerHorizontal="true"
android:src="#drawable/ic_launcher" />
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
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/sell"
android:padding="4dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
AFTER THAT
android:background="#drawable/round_button"
android:src="#drawable/ic_sell"
android:background="#drawable/round_button"
android:src="#drawable/ic_cart"
PUT THIS LINE TO YOUR TWO IMAGE BUTTONS SURELY IT WILL WORK FOR YOU
One Linear layout is enough for this. Do not put your AmountMeterView into it's own LinearLayout.
Just make one Linear layout (vertical), and put all three elements in there. Gravity center_horizontal for all elements.
Try in this way hope this will help you
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/purchase"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_launcher" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:gravity="center"
android:orientation="vertical" >
<ImageButton
android:id="#+id/sell"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:background="#drawable/round_button"
android:src="#drawable/ic_launcher" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="2"
android:orientation="vertical" >
<com.example.mobile.view.AmountMeterView
android:id="#+id/mobileAmount"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="4dp" />
</LinearLayout>
</LinearLayout>
I have a Linearlayout within a RelativeLayout that I'm trying to align to the rightmost side of the screen with margin. Example:
How should I modify the LinearLayout's properties to achieve this? thanks
Here is the XML file(the name of the LinearLayout that should be aligned to right is slide_right):
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="top"
tools:context=".MainActivity" >
<WebView android:id="#+id/webview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>
<LinearLayout
android:id="#+id/slide_left"
android:layout_width="400dp"
android:layout_height="550dp"
android:layout_marginLeft="-367dp"
android:layout_marginTop="150dp"
android:background="#drawable/left_slide"
android:orientation="vertical" >
</LinearLayout>
<LinearLayout
android:id="#+id/slide_right"
android:layout_width="400dp"
android:layout_height="550dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="-30dp"
android:orientation="horizontal"
android:background="#drawable/right_slide">
</LinearLayout>
<LinearLayout
android:id="#+id/header_linear_l"
android:layout_width="match_parent"
android:layout_height="80dp"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/mapbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/mapbt" />
<ImageButton
android:id="#+id/profilebt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/profilebt" />
<ImageButton
android:id="#+id/settingsbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/settingsbt" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<ImageButton
android:id="#+id/optionalbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/optionbt" />
<ImageButton
android:id="#+id/lvlbt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/levelbt" />
</LinearLayout>
<ProgressBar
android:id="#+id/experiencebar"
style="?android:attr/progressBarStyleHorizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
</LinearLayout>
<ImageButton
android:id="#+id/Attack_Button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/slide_left"
android:layout_marginBottom="129dp"
android:layout_marginLeft="36dp"
android:layout_toRightOf="#+id/slide_left"
android:src="#drawable/ic_launcher_old"
android:visibility="invisible" />
</RelativeLayout>
Change Your Relative layout's Property
from
android:layout_width="wrap_content"
to
android:layout_width="match_parent"
thats it... (definitely I have tested it see below snapshot)
See the following Code
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/your_relative_layout_id"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#color/white" >
<LinearLayout
android:id="#+id/your_linear_layout_id"
android:layout_width="50dip"
android:layout_height="50dip"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="-30dip"
android:background="#e42c2a"
android:orientation="horizontal" >
</LinearLayout>
</RelativeLayout>
Here
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="-30dip"
are of your use.