SlidingDrawer cannot have the NECESSARY measurements

Hi, I am getting a runtime exception:

SlidingDrawer cannot have UNSPECIFIED dimensions 

From the XML below, 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> 
+6
source share
5 answers

I had the same problem, so I started digging the source code. The main answer is what is called measure() on your SlidingDrawer using MeasureSpec.UNSPECIFIED , meaning SlidingDrawer has the ability to set its own size.

This may be due to the fact that the containing layout (or its parents) is aligned to the base or has WRAP_CONTENT as its height or width. If the containing LinearLayout has baselineAligned true, she asks all her children for their size to find the largest. And, of course, he also asks his children in size if he should wrap them.

Set android:baselineAligned="false" in any LinearLayout that contains a sliding box, and make sure that nothing containing SlidingDrawer has WRAP_CONTENT for height or width. In other words, the SlidingDrawer must have an exact size, which means that its parents must also use FILL_PARENT .

+6
source

Because your SlidingDrawer is in a ScrollView. I assume ScrollView cannot provide height, but SlidingDrawer inherits height from ScrollView and throws an exception. (I get the key from http://grepcode.com/file/repository.grepcode.com/java/ext/com.google.android/android/1.5_r4/android/widget/SlidingDrawer.java )

+4
source

You must specify a dimension for the layout_height attribute, for example android:layout_height="100dp"

+2
source

I'm actually not sure why this leads to an uncertainty about your height or width, but I can say that packing your sliding drawer in LinearLayout is probably causing the problem. Turn this code into attributes on SlidingDrawer and delete LinearLayout :

 android:layout_below="@id/linearLayout8" android:layout_width="fill_parent" android:layout_height="fill_parent" android:gravity="bottom" 

Hope this fixes it for you.

+1
source

I am afraid that the problem might be in ScrollView: it looks like you cannot place SlidingDrawer in ScrollView. Check this thread for the same issue. The guy's solution was for ScrollView Wrap to ALL EXCLUDE SlidingDrawer. Then he added both: ScrollView and SlidingDrawer in RelativeLayout - it seems to work for him, you should give him a chance (like me).

[EDIT] I did it, and here is how it works for me:

  RelativeLayout mainContainer = new RelativeLayout(context); mainContainer.setLayoutParams(new RelativeLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); ScrollView scrollView = new ScrollView(context); scrollView.setLayoutParams(new ScrollView.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT)); // Add furhter children to scrollview if you wish to // Add the scrollview to the main container mainContainer.addView(scrollView); // Create your SlidingViewer, for instance be inflating it using the layout inflater // Inflate from pre-written layout // getSystemService is only available from an Activity LayoutInflater inflater = (LayoutInflater)getSystemService( Context.LAYOUT_INFLATER_SERVICE); // We dont have the parent view yet, will be added by the layouter SlidingDrawer slidingDrawer = (SlidingDrawer) inflater.inflate(R.layout.sliding_drawer_layout, null); // Add Sliding drawer at the bottom mainContainer.addView(new SlidingDrawerWidget(context, new AttributeContainer()).getView()); 
0
source

Source: https://habr.com/ru/post/894089/


All Articles