Hi I am getting a run time exception:
SlidingDrawer cannot have UNSPECIFIED dimensions
From the below XML, Can any help on this.
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/scroll" android:layout_width="fill_parent" android:layout_height="fill_parent" android:fillViewport="true">
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="10px" android:background="@drawable/formbg">
<LinearLayout android:id="@+id/linearLayout1"
android:layout_width="fill_parent" android:layout_height="wrap_content"
android:orientation="horizontal" android:layout_alignParentTop="true"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true">
<TextView android:id="@+id/label"
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="Question Title"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#000000"
android:paddingLeft="5px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
<EditText android:id="@+id/entry"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:paddingLeft="10px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout2"
android:layout_below="@id/linearLayout1" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:paddingRight="0px" >
<TextView android:id="@+id/pass"
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="Type Description"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#000000"
android:paddingLeft="5px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
<EditText android:id="@+id/passentry"
android:layout_width="match_parent"
android:layout_height="100px"
android:textColor="#000000"
android:paddingLeft="10px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout3"
android:layout_below="@id/linearLayout2" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true">
<TextView android:id="@+id/labelbounty"
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="Enter Amount $"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#000000"
android:paddingLeft="5px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
<EditText android:id="@+id/bounty"
android:numeric="decimal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:paddingLeft="10px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout4"
android:layout_below="@id/linearLayout3" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true">
<TextView android:id="@+id/duedatelabel"
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="Due Date"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#000000"
android:paddingLeft="10px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px" />
<Button android:id="@+id/pickDate"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textColor="#000000"
android:paddingLeft="10px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
android:text="Select Due Date"/>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout5"
android:layout_below="@id/linearLayout4" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true">
<TextView android:id="@+id/labelprimary"
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="Category"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#000000"
android:paddingLeft="10px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
<Spinner
android:id="@+id/primarycategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="@string/planet_prompt"
android:textColor="#000000"
android:paddingLeft="15px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout6"
android:layout_below="@id/linearLayout5" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true">
<TextView android:id="@+id/labelsecondary"
android:layout_width="120px"
android:layout_height="wrap_content"
android:text="Sub Category"
android:textStyle="bold"
android:textSize="12sp"
android:textColor="#000000"
android:paddingLeft="10px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
<Spinner
android:id="@+id/secondarycategory"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:prompt="@string/secondary_category"
android:textColor="#000000"
android:paddingLeft="15px"
android:paddingRight="5px"
android:paddingTop="10px"
android:paddingBottom="10px"
/>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout7"
android:layout_below="@id/linearLayout6" android:layout_width="wrap_content"
android:padding="10px"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:paddingRight="10px" android:paddingLeft="10px">
<Button android:id="@+id/button1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Add Attachment"
>
</Button>
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout8"
android:layout_below="@id/linearLayout7" android:layout_width="wrap_content"
android:padding="10px"
android:layout_height="wrap_content" android:orientation="horizontal"
android:layout_alignParentLeft="true" android:layout_alignParentRight="true" android:paddingRight="10px" android:paddingLeft="10px">
<Button android:id="@+id/askNow"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:text="Post Question" />
</LinearLayout>
<LinearLayout android:id="@+id/linearLayout9"
android:layout_below="@id/linearLayout8"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
android:orientation="vertical">
<SlidingDrawer android:id="@+id/SlidingDrawer" android:handle="@+id/slideHandleButton" android:content="@+id/contentLayout" android:topOffset="50dip" android:layout_width="fill_parent" android:layout_height="fill_parent">
<Button android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/slideHandleButton" android:background="@drawable/closearrow"></Button>
<LinearLayout android:id="@+id/contentLayout" android:layout_width="match_parent" android:layout_height="match_parent"
android:orientation="vertical" android:gravity="center"
android:background="#FF444444">
<Button android:id="@+id/asknew" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Ask New Question"></Button>
<Button android:id="@+id/logout" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Log Out"></Button>
</LinearLayout>
</SlidingDrawer>
</LinearLayout>
<android.view.SurfaceView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
>
</android.view.SurfaceView>
</RelativeLayout>
</ScrollView>
I was having the same issue so I went digging in the source code. The basic answer is that something called measure()
on your SlidingDrawer using MeasureSpec.UNSPECIFIED
, i.e. the SlidingDrawer is allowed to set its own size.
It could be caused by the containing layout (or its parents) being base-aligned or having WRAP_CONTENT
as its height or width. If the containing LinearLayout has baselineAligned
set true, it asks all its children for their size to find the largest one. And of course it also asks its children for their size if it's supposed to wrap them.
Set android:baselineAligned="false"
in any LinearLayout that contains the sliding drawer and ensure that nothing containing the SlidingDrawer has WRAP_CONTENT for height or width. In other words, the SlidingDrawer must have an exact size defined, which means its parents must also if you use FILL_PARENT
.
Because your SlidingDrawer is in ScrollView. My guess is, because ScrollView is unable to provide height, but SlidingDrawer inherit the height from ScrollView, and caused the exception to throw. (I get the clue from http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/SlidingDrawer.java)
You have to specify a dimension for layout_height attribute, like android:layout_height="100dp"
I'm not actually sure why this is causing your height or width values to be unspecified, but I can tell you that wrapping your sliding drawer in a LinearLayout is probably causing the problem. Turn this code into attributes on the SlidingDrawer
and remove the LinearLayout
:
android:layout_below="@id/linearLayout8"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="bottom"
Hopefully this fixes it for you.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With