I want to create a button which will overlay between 2 layouts.
I am using Linear Layout and added appropriate weight to it.
Have attached a screen shot for reference.
Here is my XML
tag.xml :
<?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:gravity="center"
android:orientation="vertical"
android:weightSum="100" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="30"
android:background="#color/greyColor"
android:gravity="center" >
<ImageView
android:id="#+id/ximgvwCamera"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/camera_big" />
</RelativeLayout>
<ScrollView
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="70"
android:background="#android:color/white" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:background="#android:color/white"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_margin="5dp"
android:padding="5dp"
android:text="#string/strQ1"
android:textAppearance="#android:style/TextAppearance.Medium"
android:textColor="#android:color/darker_gray" />
</LinearLayout>
</ScrollView>
Please help me in this.
Thanks in advance!
Try this it will working...
<FrameLayout 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:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="150dp" >
<ImageView
android:id="#+id/imageCover"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="fitXY"
android:src="#drawable/image_top" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:background="#drawable/image_bottom"
android:layout_height="match_parent" >
</LinearLayout>
</LinearLayout>
<ImageView
android:id="#+id/imageProfile"
android:layout_width="100dp"
android:layout_height="100dp"
android:layout_gravity="end"
android:layout_marginTop="100dp"
android:src="#drawable/ic_launcher" />
</FrameLayout>
View like this
You need a relative layout. Set image alignt to right-top and set margin top appropriately.
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/first"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:src="#drawable/firstImage" />
<ImageView
android:layout_width="20dp"
android:layout_height="20dp"
android:layout_alignParentRight="true"
android:layout_centerVertical="true"
android:layout_marginRight="5dp"
android:src="#drawable/middleImage" >
</ImageView>
<RelativeLayout
android:id="#+id/second"
android:layout_width="fill_parent"
android:layout_height="70dp"
android:layout_below="#id/first"
android:src="#drawable/share_over" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginBottom="20dp"
android:orientation="horizontal" >
<ImageView
android:id="#+id/YES"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/YES" />
<ImageView
android:id="#+id/NO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/NO" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
Divide your image TOP-MIDDLE-BOTTOM(layout). Your size looking like above but
you can change width/height size.
Related
I have to customize a checkbox to show 2 different state while checked, i am using the following 2 images :
My custom selector is defined as follows:
<?xml version="1.0" encoding="utf-8"?>
<selector xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="#drawable/favourite_normal" android:state_checked="false"/>
<item android:drawable="#drawable/favourite_choose" android:state_checked="true"/>
<item android:drawable="#drawable/favourite_normal"/>
But thing is i am not getting proper result as in the image does not fills my checkbox view properly if i change the height and width of the checkbox which i have to do to adjust. The result i am getting like this:
The complete layout is given below :
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="1">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="74dp"
android:background="#drawable/bottom_bav_btn">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:orientation="horizontal"
android:layout_width="80dp"
android:layout_height="match_parent"
android:id="#+id/linearLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/jokeListViewBackButton"
android:src="#drawable/back_screen_button_normal"
android:layout_margin="10dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_toRightOf="#+id/linearLayout"
android:layout_toLeftOf="#+id/linearLayout2"
android:layout_toStartOf="#+id/linearLayout2"
android:weightSum="1">
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent">
<TextView
android:layout_width="fill_parent"
android:layout_height="37dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/jokeTitleTextView"
android:gravity="center_vertical|center_horizontal"
android:textColor="#color/fontWhiteColor" />
<TextView
android:layout_width="fill_parent"
android:layout_height="37dp"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="0/0"
android:id="#+id/jokeCountTxt"
android:gravity="center_vertical|center_horizontal"
android:textColor="#color/fontWhiteColor" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="80dp"
android:layout_height="match_parent"
android:layout_alignParentTop="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:id="#+id/linearLayout2"
android:gravity="center_vertical|center_horizontal">
<CheckBox
android:layout_width="40dp"
android:layout_height="40dp"
android:id="#+id/checkBox"
android:button="#drawable/custom_favourite_selector"
android:gravity="center_vertical|center_horizontal"
android:checked="false" />
</LinearLayout>
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="300dp"
android:weightSum="1"
android:background="#color/listViewBody"
android:layout_weight="0.71">
<ScrollView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:id="#+id/scrollView" >
<com.gravityapps.framework.Utils.CustomTextView
android:layout_width="wrap_content"
android:layout_height="fill_parent"
android:text=""
android:id="#+id/jokeTextView"
android:layout_below="#+id/imageView"
android:layout_centerHorizontal="true"
android:gravity="center"
android:textSize="25dp"
android:layout_alignParentBottom="true"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp" />
</ScrollView>
</LinearLayout>
<LinearLayout android:id="#+id/navbar"
android:layout_width="fill_parent"
android:layout_height="80dp"
android:orientation="horizontal">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/prevButtonLayout"
android:clickable="true">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView2"
android:background="#drawable/previous_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/randPrevButtonLayout"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView3"
android:background="#drawable/reverse_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/linearLayout5"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView4"
android:background="#drawable/copy_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/linearLayout6"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView7"
android:background="#drawable/share_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/randNextButtonLayout"
android:clickable="true" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView5"
android:background="#drawable/forward_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:clickable="true"
android:layout_weight="1"
android:background="#drawable/bottom_nav_back"
android:id="#+id/nextButtonLayout">
<ImageView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/imageView6"
android:background="#drawable/next_btn_normal"
android:layout_margin="15dp" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
I am not sure why i am getting this result. Any help would be appreciated. Thanks
The size of Checkbox 40dp*40dp smaller than the image you defined in selector.
use wrap_content instead of static dimensions.
Depending on the previous answer, if you don't want your checkbox to be larger, than you will have to resize your images. I think these are your best options, either you wrap_content your checkbox width and height or you resize your image resources into smaller, ex. 40*40px
I've made a layout that worked fine with a vertical scroll view, but I need to make another one with a horizontal scroll view.
I just changed ScrollView to HorizontalScrollView:
<?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" >
<HorizontalScrollView
android:layout_weight="1"
android:scrollbars="none"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="#string/activity_visibilidade_cronologia_aula_subtitulo"
android:textSize="16dp" />
<ImageButton
android:id="#+id/activity_visibilidade_cronologia_aula_btn_info"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/btn_info" />
</RelativeLayout>
<LinearLayout
android:id="#+id/activity_visibilidade_cronologia_aula_linear_conteudo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
<Button
android:id="#+id/activity_visibilidade_cronologia_aula_btn_confimar"
android:layout_width="165dp"
android:layout_height="35dp"
android:layout_centerVertical="true"
android:layout_gravity="right"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/botao_add_confirmar"
android:text="#string/dialogo_alterar_classe_confirmar"
android:textColor="#color/branco" />
</LinearLayout>
</HorizontalScrollView>
</LinearLayout>
And its result is:
Why doesn't HorizontalScrollView fills the parent, is there something wrong?
I solved merging all your advices and also using android:fillViewport="true" my final code is:
<?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" >
<include layout="#layout/layout_titulo_views" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_marginLeft="10dp"
android:text="#string/activity_visibilidade_cronologia_aula_subtitulo"
android:textSize="16dp" />
<ImageButton
android:id="#+id/activity_visibilidade_cronologia_aula_btn_info"
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_alignParentRight="true"
android:layout_marginRight="10dp"
android:background="#null"
android:scaleType="fitXY"
android:src="#drawable/btn_info" />
</RelativeLayout>
<HorizontalScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fillViewport="true"
android:scrollbars="horizontal" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:id="#+id/activity_visibilidade_cronologia_aula_linear_conteudo"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
<Button
android:id="#+id/activity_visibilidade_cronologia_aula_btn_confimar"
android:layout_width="165dp"
android:layout_height="35dp"
android:layout_centerVertical="true"
android:layout_gravity="right"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginTop="10dp"
android:background="#drawable/botao_add_confirmar"
android:text="#string/dialogo_alterar_classe_confirmar"
android:textColor="#color/branco" />
</LinearLayout>
</LinearLayout>
Thank you all
I found teh problem. In addition to removing the weight sum, you need to change the linear layout orientation to horizontal.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="horizontal" >
The android layout lacks proportion when I set the background of Imagebutton.
And the code of xml is like the following:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="vertical" >
<FrameLayout
android:id="#+id/player_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="#+id/buttonLayout" >
<FrameLayout
android:id="#+id/player_surface_frame"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" >
<SurfaceView
android:id="#+id/player_surface"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_gravity="center" />
</FrameLayout>
</FrameLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/findCameraButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:text="#string/label_find_camera" />
<Button
android:id="#+id/SettingButton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:text="#string/Camera_WiFi_setup" />
<ImageButton
android:id="#+id/FileSavebutton"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:background="#drawable/save_in_camera" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/TimeStampLabel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="10dip"
android:text=""
android:textColor="#ffff00"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<Button
android:id="#+id/snapshotButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="#string/label_app_snapshot" />
<Button
android:id="#+id/recordButton"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="4"
android:text="#string/label_app_record" />
<ImageButton
android:id="#+id/photo_record_mode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:background="#drawable/turn_to_photomode"/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
How to setup can make the top of LinearLayout no deformation like the LinearLayout of bottom ?
Have you tried changing all the android:layout_height values from match_parent to wrap_content?
i think you should use scaleType to get your image look nice
prefer fitXY
like that
android:scaleType="fitXY"
put inside your xml to be whole code like that
<ImageButton
android:id="#+id/photo_record_mode"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="4"
android:background="#drawable/turn_to_photomode"
android:scaleType="fitXY"/>
i am working on a layout with 3 buttons and an image view i call the imageview as the first child of the parent however when i build it on actual device the imageview goes down after the buttons... really weird....
heres the xml file:
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<ImageView
android:id="#+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/111"
android:visibility="visible" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/222"
android:visibility="visible"
/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_medium"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/highscores_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/highscore_btn"
android:visibility="visible" />
<Button
android:id="#+id/more_apps_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_medium"
android:background="#drawable/333"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
is this because of the size of the imageview? it is really large so i put it in xxhdpi folder so it will be reduced. any thoughts? thanks
// try this
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#drawable/background" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:gravity="center"
android:layout_gravity="center"
android:orientation="vertical">
<LinearLayout
android:layout_height="wrap_content"
android:layout_width="match_parent">
<ImageView
android:id="#+id/title_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/111"
android:visibility="visible" />
</LinearLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/222"
android:visibility="visible"/>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="#dimen/margin_medium"
android:gravity="center"
android:orientation="horizontal" >
<Button
android:id="#+id/highscores_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/highscore_btn"
android:visibility="visible" />
<Button
android:id="#+id/more_apps_button"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="#dimen/margin_medium"
android:background="#drawable/333"
android:visibility="visible" />
</LinearLayout>
</LinearLayout>
</FrameLayout>
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.