android relative layout issue with button - android

I have below relative layout:
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:paddingTop="5dp" >
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip" />
<View
android:id="#+id/buttonDivider"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip" />
<Button
android:id="#+id/btnOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#id/buttonDivider"
android:text="Open" />
<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:layout_toRightOf="#id/buttonDivider"
android:text="Close" />
</RelativeLayout>
And it generates button like this:
I tried modifying properties, given enough time but can't get it right :(
How can I make it so three buttons appear in sequence while equally occupying width from parent (currently they are not equally distributed as shown in image):
Open Delete Close
Thanks for the help

Do not use relative layout. The solutions is:
Use a horizontal linear layout for the parent layout.
Set android:weightSum="3" for the linear layout.
For each button set android:layout_width="0dp" and android:layout_weight="1". This will distribute them evenly.

You can simply achieve your requirement using LinearLayout with android:layout_weight attribute as follows...
<LinearLayout
android:layout_width="match_parent"
android:layout_height="48dip"
android:orientation="horizontal"
android:paddingTop="5dp"
android:weightSum="3" >
<Button
android:id="#+id/btnOpen"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Open" />
<Button
android:id="#+id/btnDelete"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Close" />
</LinearLayout>

<RelativeLayout
android:layout_width="match_parent"
android:layout_height="48dp"
android:paddingTop="5dp" >
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip" />
<View
android:id="#+id/buttonDivider"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip" />
<Button
android:id="#+id/btnOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_toLeftOf="#id/buttonDivider"
android:text="Open" />
<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_toRightOf="#+id/btnOpen"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/btnDelete"
android:text="Close" />

LinearLayout is much easier to use in such case:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="48dp"
android:paddingTop="5dp">
<Button
android:id="#+id/btnOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Open" />
<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Close" />
</LinearLayout>

Change the code with following 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="48dp"
android:paddingTop="5dp" >
<View
android:layout_width="match_parent"
android:layout_height="1dip"
android:layout_alignParentTop="true"
android:layout_marginLeft="4dip"
android:layout_marginRight="4dip" />
<View
android:id="#+id/buttonDivider"
android:layout_width="1dip"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginBottom="4dip"
android:layout_marginTop="4dip" />
<Button
android:id="#+id/btnOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:text="Open" />
<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerInParent="true"
android:text="Delete" />
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:text="Close" />
</RelativeLayout>

If you want that to be center horizontal or vertical or both give its respective property to the parent relative layout.
Both Center Vertical or Horizontal- android:layout_centerInParent="true"
Horizontal- android:layout_centerHorizontal="true"
Vertical- android:layout_centerVertical="true"

Try this:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="0dp"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="#+id/btnOpen"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Open" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="#+id/btnDelete"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Delete" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:gravity="center"
android:layout_height="wrap_content"
android:layout_weight="1" >
<Button
android:id="#+id/btnClose"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Close" />
</LinearLayout>
</LinearLayout>

Related

I have two realtive layouts , one over the other .But keyboard of one layout is pushing the other layout out of the screen

I have two Relative layouts. Such that , one is over the other .
<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"
tools:context="com.mettl.zobbr.SliderActivity" >
<RelativeLayout
android:id="#+id/dddd"
android:layout_width="fill_parent"
android:isScrollContainer="false"
android:layout_height="wrap_content" >
<ImageView
android:id="#+id/Button06"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_height="72dp"
android:layout_alignParentLeft="true"
android:isScrollContainer="false"
android:layout_alignParentTop="true"
android:background="#drawable/spin_title" />
<Button
android:id="#+id/button9"
style="?android:attr/buttonStyleSmall"
android:layout_width="wrap_content"
android:layout_marginLeft="85dp"
android:background="#00000000"
android:isScrollContainer="false"
android:onClick="BackToJob"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button8"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true" />
<Button
android:id="#+id/button8"
style="?android:attr/buttonStyleSmall"
android:background="#00000000"
android:isScrollContainer="false"
android:layout_marginLeft="160dp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:onClick="BackToLoc"
android:layout_alignLeft="#+id/button7"
android:layout_alignParentTop="true" />
</RelativeLayout>
<ScrollView
android:layout_below="#+id/dddd"
android:layout_width="fill_parent"
android:background="#drawable/spin_back"
android:layout_height="fill_parent"
android:layout_alignParentBottom="true"
>
<RelativeLayout
android:layout_below="#+id/dddd"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
<kankan.wheel.widget.WheelView android:id="#+id/hour"
android:layout_height="wrap_content"
android:layout_marginLeft="85dp"
android:layout_marginTop="70dp"
android:layout_width="75dp"/>
<kankan.wheel.widget.WheelView android:id="#+id/second"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:layout_marginTop="70dp"
android:layout_toRightOf="#+id/hour"
android:layout_width="75dp"/>
<TextView
android:id="#+id/textView124"
android:layout_toRightOf="#+id/second"
android:layout_width="wrap_content"
android:textSize="25dp"
android:textColor="#000000"
android:layout_height="wrap_content"
android:layout_marginTop="70dp"
android:layout_marginLeft="10dp"
android:layout_alignParentRight="true"
android:paddingTop="65dp"
android:text="000/-" />
<EditText
android:id="#+id/textView1234"
android:layout_toRightOf="#+id/second"
android:layout_width="wrap_content"
android:textSize="25dp"
android:layout_marginLeft="100dp"
android:layout_marginRight="100dp"
android:gravity="center"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:maxLength="10"
android:inputType="number"
android:focusableInTouchMode="true"
android:layout_height="wrap_content"
android:layout_below="#+id/hour"
android:paddingTop="95dp"
/>
</RelativeLayout>
</ScrollView>
<LinearLayout
android:id="#+id/btnLL"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
<Button
android:id="#+id/button12"
android:layout_width="0dp"
android:layout_height="40dp"
android:layout_weight="3"
android:onClick="refresh"
android:layout_marginLeft="10dp"
android:layout_marginRight="10dp"
android:layout_marginBottom="10dp"
android:background="#drawable/veri_button"/>
<Button
android:id="#+id/button2"
android:layout_width="50dp"
android:layout_height="40dp"
android:layout_marginBottom="10dp"
android:layout_marginRight="10dp"
android:layout_marginLeft="10dp"
android:layout_weight="1"
android:background="#drawable/button_background_selector"
/>
</LinearLayout>
</RelativeLayout>
But when I click on the edit text of the second layout . The softKeyboard pushes the the first layout out of the screen .(The first layout ,is located on top of the screen ).
I have used android:isScrollContainer="false" ,yet the required result was not achieved.
I have added android:windowSoftInputMode="adjustPan" to the manifest as well . Still did not work.
try in your manifest instead of:
android:windowSoftInputMode="adjustPan"
use:
android:windowSoftInputMode="adjustNothing"

adapt bottom menu to all screens

I have designed one bottom menu in mu android app
it works fine in the screen which I work on
but if I change the screen , it doesn't fill all the width of screen even if I set width of the relativeLayout to fill_parent
here is the code of the menu :
<RelativeLayout
android:id="#+id/bar_bas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:background="#null"
android:clickable="true" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/right_left"
android:text="test"
android:textColor="#bfd2b0" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/relativeLayout1"
android:clickable="true" >
<Button
android:id="#+id/btn_circle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/left_circle"
android:text="test"
android:textColor="#bfd2b0" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="-40dp"
android:layout_toRightOf="#+id/relativeLayout2"
android:clickable="true" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/circle"
android:text="test"
android:textColor="#bfd2b0" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="-38dp"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/relativeLayout3"
android:clickable="true" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/right_circle"
android:text="test"
android:textColor="#bfd2b0" />
</RelativeLayout>
<RelativeLayout
android:id="#+id/relativeLayout5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/relativeLayout4"
android:clickable="true" >
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/right_left"
android:text="test"
android:textColor="#bfd2b0" />
</RelativeLayout>
</RelativeLayout>
and here is how it is in my screen : http://s23.postimg.org/m3h37utuj/image.png
and here an example of other screen(tablet screen) : http://s24.postimg.org/hd0ibrahh/image.png
how can I fix this issue
Try this..
<LinearLayout
android:id="#+id/bar_bas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:orientation="horizontal" >
<Button
android:layout_height="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"
android:background="#drawable/right_left"
android:text="test"
android:textColor="#bfd2b0" />
<Button
android:id="#+id/btn_circle"
android:layout_height="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"
android:background="#drawable/left_circle"
android:text="test"
android:textColor="#bfd2b0" />
<Button
android:layout_height="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"
android:background="#drawable/circle"
android:text="test"
android:textColor="#bfd2b0" />
<Button
android:layout_height="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"
android:background="#drawable/right_circle"
android:text="test"
android:textColor="#bfd2b0" />
<Button
android:layout_height="0dp"
android:layout_weight="0.2"
android:layout_height="wrap_content"
android:background="#drawable/right_left"
android:text="test"
android:textColor="#bfd2b0" />
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/bar_bas"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#ff00ff"
android:text="test"
android:layout_weight="1"
android:textColor="#bfd2b0" />
<Button
android:id="#+id/btn_circle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#FF0000"
android:text="test"
android:layout_weight="1"
android:textColor="#bfd2b0" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#ff00AA"
android:text="test"
android:layout_weight="1"
android:textColor="#bfd2b0" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#ffaaff"
android:text="test"
android:layout_weight="1"
android:textColor="#bfd2b0" />
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:background="#00AAff"
android:text="test"
android:layout_weight="1"
android:textColor="#bfd2b0" />
</LinearLayout>
Check this one, wrap_parent means it will take as less space as it can.

Android: TableLayout Row Not Centering via XML

I'm trying to center a table row using XML in Android, but I'm having a problem where it's over to the right just a smidge too much for two of my rows that only contain two buttons. Here's my code, and I have a screen shot of how it looks
<TableLayout
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">
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center">
<ImageView
android:id="#+id/hiragana_multiple_choice_main_image"
android:gravity="center"
android:layout_width="fill_parent"
android:layout_height="match_parent"/>
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:padding="30dp">
<Button
android:id="#+id/hiragana_multiple_choice_button_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" />
<Button
android:id="#+id/hiragana_multiple_choice_button_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_weight="1" />
</TableRow>
<TableRow
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="30dp"
android:gravity="center">
<Button
android:id="#+id/hiragana_multiple_choice_button_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button
android:id="#+id/hiragana_multiple_choice_button_4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</TableRow>
</TableLayout>
http://www.ptrprograms.com/multiple_choice_offset.png
Thanks!
try to use LinearLayout instead of tablelayout, it will fix it to center and also use fillparent and wrap content for best practice.
Try these Way....
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:layout_marginTop="65dp"
android:src="#drawable/ic_launcher" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/imageView1"
android:layout_marginTop="59dp"
android:layout_toLeftOf="#+id/imageView1"
android:text="Button" />
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button1"
android:layout_alignBottom="#+id/button1"
android:layout_alignParentRight="true"
android:layout_toRightOf="#+id/imageView1"
android:text="Button" />
<Button
android:id="#+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignRight="#+id/button1"
android:layout_below="#+id/button1"
android:layout_marginTop="68dp"
android:text="Button" />
<Button
android:id="#+id/button4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/button3"
android:layout_alignBottom="#+id/button3"
android:layout_alignLeft="#+id/button2"
android:layout_alignParentRight="true"
android:text="Button" />
</RelativeLayout>

How to create a divider in a dialog box

I have a dialog box with two buttons at the bottom. How do I create a divider above these buttons? My XML is as follows:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content"
android:layout_height="400dp"
>
<ImageView
android:id="#+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/username"
android:layout_alignParentLeft="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<Button
android:id="#+id/start"
android:textSize="18sp"
android:layout_marginRight="2dip"
android:layout_width="wrap_content"
android:layout_marginBottom="5dip"
android:padding="5dip"
android:layout_height="fill_parent"
android:text="Start" />
<Button
android:id="#+id/cancel"
android:textSize="18sp"
android:layout_marginLeft="2dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:textColor="#000000" />
</LinearLayout>
</RelativeLayout>
Using View
<View android:layout_height="2px" android:layout_width="fill_parent"
android:background="#android:color/black"
/>
Simply add a ImageView and provide the following attribute,
<ImageView android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="#color/white"
android:padding="5dip"/>
There is nothing like a Divider attribute that you could set for a Layout. Dividers are available for ListView only.
So you might have to change your linear layout like this,
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<ImageView android:layout_width="fill_parent"
android:layout_height="3dip"
android:background="#color/white"
android:padding="5dip"/>
</LinearLayout>
<LinearLayout android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/start"
android:textSize="18sp"
android:layout_marginRight="2dip"
android:layout_width="wrap_content"
android:layout_marginBottom="5dip"
android:padding="5dip"
android:layout_height="fill_parent"
android:text="Start" />
<Button
android:id="#+id/cancel"
android:textSize="18sp"
android:layout_marginLeft="2dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>
I just came up something based on Nirav's answer
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="254dp"
android:layout_height="wrap_content"
android:background="#drawable/dialogbox_bg"
android:orientation="vertical" >
<ImageView
android:layout_width="fill_parent"
android:layout_height="50dp"
android:gravity="center"
android:text="#string/selectattachment"
android:textColor="#color/white"
android:textSize="20sp"
android:textStyle="bold" />
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:background="#color/blue" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:orientation="horizontal">
<Button
android:id="#+id/start"
android:textSize="18sp"
android:layout_marginRight="2dip"
android:layout_width="wrap_content"
android:layout_marginBottom="5dip"
android:padding="5dip"
android:layout_height="fill_parent"
android:text="Start" />
<Button
android:id="#+id/cancel"
android:textSize="18sp"
android:layout_marginLeft="2dip"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cancel"
android:textColor="#000000" />
</LinearLayout>
</LinearLayout>

Slidingdrawer position changes while adjust it's height

I have created sliding drawer for my relative layout which includes some buttons. But when I adjust the height of the drawer the drawer button position changes instead of it's height. Here is my xml file.......
<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
android:visibility="visible"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
xmlns:android="http://schemas.android.com/apk/res/android">
<com.measure.sizemesurment2.MyView
android:id="#+id/DrawViewId"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.measure.sizemesurment2.MyView >
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="wrap_content"
android:layout_height="100dip"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/arrow" />
<RelativeLayout
android:id="#id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/left"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:onClick="ButtonOnClick"
android:src="#drawable/left" />
<ImageButton
android:id="#+id/right"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="40dp"
android:onClick="ButtonOnClick"
android:src="#drawable/right" />
<ImageButton
android:id="#+id/up"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="80dp"
android:onClick="ButtonOnClick"
android:src="#drawable/up" />
<ImageButton
android:id="#+id/down"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="120dp"
android:onClick="ButtonOnClick"
android:src="#drawable/down" />
<Button
android:id="#+id/plus"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="180dp"
android:onClick="ButtonOnClick"
android:text="+"
android:textSize="20dp" />
<Button
android:id="#+id/minus"
android:layout_width="40dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="220dp"
android:onClick="ButtonOnClick"
android:text="-"
android:textSize="20dp" />
<Button
android:id="#+id/ok"
android:layout_width="60dp"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_marginLeft="260dp"
android:onClick="ButtonOnClick"
android:text="OK"
android:textSize="20dp" />
</RelativeLayout>
</SlidingDrawer>
</FrameLayout>
where MyView is a class used to draw on canvas. When I set SlidingDrawer height to fill parent I am getting button on the bottom side of my layout. But it's height is parent's height, I need limited height and all my buttons should position on the bottom of the layout...
Thanks in advance.....
Hi here is my image I am getting, First one is resulted when set siding drwer height "fill_parent" and the second is for 100dip
Its happening because all your buttons are residing in RelativeLayout which is the child of SliderDrawable, So you need to take out your button from it,
Do something like this
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:visibility="visible" >
<SlidingDrawer
android:id="#+id/drawer"
android:layout_width="wrap_content"
android:layout_height="50dp"
android:content="#+id/content"
android:handle="#+id/handle" >
<Button
android:id="#+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/white"
android:textSize="50dp"
android:text="^"
android:textColor="#android:color/black" />
<RelativeLayout
android:id="#+id/content"
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
</RelativeLayout>
</SlidingDrawer>
<com.measure.sizemesurment2.MyView
android:layout_below="#+id/drawer"
android:layout_above="#+id/linear_bottom"
android:id="#+id/DrawViewId"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
</com.measure.sizemesurment2.MyView >
<LinearLayout
android:id="#+id/linear_bottom"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:orientation="horizontal" >
<ImageButton
android:id="#+id/left"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="ButtonOnClick" />
<ImageButton
android:id="#+id/right"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="ButtonOnClick" />
<ImageButton
android:id="#+id/up"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="ButtonOnClick" />
<ImageButton
android:id="#+id/down"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="ButtonOnClick" />
<Button
android:id="#+id/plus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="ButtonOnClick"
android:text="+" />
<Button
android:id="#+id/minus"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="ButtonOnClick"
android:text="-" />
<Button
android:id="#+id/ok"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:onClick="ButtonOnClick"
android:text="OK" />
</LinearLayout>
</RelativeLayout>
Output:

Categories

Resources