Haris
Haris

Reputation: 14053

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

image1 image2

Upvotes: 1

Views: 859

Answers (1)

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:

enter image description here

Upvotes: 3

Related Questions