SlidingDrawer不能有不定的尺寸 [英] SlidingDrawer cannot have UNSPECIFIED dimensions
问题描述
我得到一个运行时异常:
SlidingDrawer不能有不定的尺寸
从下面的XML,这个可以在任何帮助。
< XML版本=1.0编码=UTF-8&GT?;
<滚动型的xmlns:机器人=http://schemas.android.com/apk/res/android机器人:ID =@ + ID /卷动的Android:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT机器人:fillViewport =真正的>
< RelativeLayout的的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:填充=10px的机器人:背景=@可绘制/ formbg>
<的LinearLayout机器人:ID =@ + ID / linearLayout1
机器人:layout_width =FILL_PARENT机器人:layout_height =WRAP_CONTENT
机器人:方向=横向机器人:layout_alignParentTop =真
机器人:layout_alignParentLeft =真正的机器人:layout_alignParentRight =真正的>
< TextView的机器人:ID =@ + /标记
机器人:layout_width =120px
机器人:layout_height =WRAP_CONTENT
机器人:文本=问题标题
机器人:TEXTSTYLE =黑体
机器人:TEXTSIZE =12SP
机器人:文字颜色=#000000
机器人:以下属性来=5像素
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
< EditText上机器人:ID =@ + ID /条目
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=#000000
机器人:以下属性来=10px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / linearLayout2
机器人:layout_below =@ ID / linearLayout1机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:方向=横向
机器人:layout_alignParentLeft =真正的机器人:layout_alignParentRight =真正的机器人:paddingRight =0px>
< TextView的机器人:ID =@ + ID /密码
机器人:layout_width =120px
机器人:layout_height =WRAP_CONTENT
机器人:文本=类型说明
机器人:TEXTSTYLE =黑体
机器人:TEXTSIZE =12SP
机器人:文字颜色=#000000
机器人:以下属性来=5像素
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
< EditText上机器人:ID =@ + ID / passentry
机器人:layout_width =match_parent
机器人:layout_height =100像素
机器人:文字颜色=#000000
机器人:以下属性来=10px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / linearLayout3
机器人:layout_below =@ ID / linearLayout2机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:方向=横向
机器人:layout_alignParentLeft =真正的机器人:layout_alignParentRight =真正的>
< TextView的机器人:ID =@ + ID / labelbounty
机器人:layout_width =120px
机器人:layout_height =WRAP_CONTENT
机器人:文本=输入金额$
机器人:TEXTSTYLE =黑体
机器人:TEXTSIZE =12SP
机器人:文字颜色=#000000
机器人:以下属性来=5像素
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
< EditText上机器人:ID =@ + ID /赏金
机器人:数字=十进制
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=#000000
机器人:以下属性来=10px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / linearLayout4
机器人:layout_below =@ ID / linearLayout3机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:方向=横向
机器人:layout_alignParentLeft =真正的机器人:layout_alignParentRight =真正的>
< TextView的机器人:ID =@ + ID / duedatelabel
机器人:layout_width =120px
机器人:layout_height =WRAP_CONTENT
机器人:文本=到期日
机器人:TEXTSTYLE =黑体
机器人:TEXTSIZE =12SP
机器人:文字颜色=#000000
机器人:以下属性来=10px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的/>
<按钮机器人:ID =@ + ID / pickDate
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:文字颜色=#000000
机器人:以下属性来=10px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
机器人:文本=选择到期日/>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / linearLayout5
机器人:layout_below =@ ID / linearLayout4机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:方向=横向
机器人:layout_alignParentLeft =真正的机器人:layout_alignParentRight =真正的>
< TextView的机器人:ID =@ + ID / labelprimary
机器人:layout_width =120px
机器人:layout_height =WRAP_CONTENT
机器人:文本=类别
机器人:TEXTSTYLE =黑体
机器人:TEXTSIZE =12SP
机器人:文字颜色=#000000
机器人:以下属性来=10px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
<微调
机器人:ID =@ + ID / primarycategory
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:提示=@字符串/ planet_prompt
机器人:文字颜色=#000000
机器人:以下属性来=15px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / linearLayout6
机器人:layout_below =@ ID / linearLayout5机器人:layout_width =WRAP_CONTENT
机器人:layout_height =WRAP_CONTENT机器人:方向=横向
机器人:layout_alignParentLeft =真正的机器人:layout_alignParentRight =真正的>
< TextView的机器人:ID =@ + ID / labelsecondary
机器人:layout_width =120px
机器人:layout_height =WRAP_CONTENT
机器人:文本=子类别
机器人:TEXTSTYLE =黑体
机器人:TEXTSIZE =12SP
机器人:文字颜色=#000000
机器人:以下属性来=10px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
<微调
机器人:ID =@ + ID / secondarycategory
机器人:layout_width =match_parent
机器人:layout_height =WRAP_CONTENT
机器人:提示=@字符串/ secondary_category
机器人:文字颜色=#000000
机器人:以下属性来=15px的
机器人:paddingRight =5像素
机器人:paddingTop =10px的
机器人:paddingBottom会=10px的
/>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / linearLayout7
机器人:layout_below =@ ID / linearLayout6机器人:layout_width =WRAP_CONTENT
机器人:填充=10px的
机器人:layout_height =WRAP_CONTENT机器人:方向=横向
机器人:layout_alignParentLeft =真正的机器人:layout_alignParentRight =真正的机器人:paddingRight =10px的机器人:以下属性来=10px的>
<按钮机器人:ID =@ + ID /按钮1
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:文本=添加附件
>
< /按钮>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / linearLayout8
机器人:layout_below =@ ID / linearLayout7机器人:layout_width =WRAP_CONTENT
机器人:填充=10px的
机器人:layout_height =WRAP_CONTENT机器人:方向=横向
机器人:layout_alignParentLeft =真正的机器人:layout_alignParentRight =真正的机器人:paddingRight =10px的机器人:以下属性来=10px的>
<按钮机器人:ID =@ + ID / askNow
机器人:layout_width =FILL_PARENT
机器人:layout_height =WRAP_CONTENT
机器人:layout_alignParentRight =真
机器人:文本=留言咨询/>
< / LinearLayout中>
<的LinearLayout机器人:ID =@ + ID / linearLayout9
机器人:layout_below =@ ID / linearLayout8
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
机器人:重力=底
机器人:方向=垂直>
< SlidingDrawer机器人:ID =@ + ID / SlidingDrawer机器人:拉手=@ + ID / slideHandleButton机器人:CONTENT =@ + ID / contentLayout机器人:topOffset =50dip机器人:layout_width =FILL_PARENT机器人:layout_height =FILL_PARENT>
<按钮机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:ID =@ + ID / slideHandleButton机器人:背景=@可绘制/ closearrow>< /按钮>
<的LinearLayout机器人:ID =@ + ID / contentLayout机器人:layout_width =match_parent机器人:layout_height =match_parent
机器人:方向=垂直安卓重力=中心
机器人:后台=#FF444444>
<按钮机器人:ID =@ + ID / asknew机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文本=提出新问题>< /按钮>
<按钮机器人:ID =@ + ID /注销机器人:layout_width =WRAP_CONTENT机器人:layout_height =WRAP_CONTENT机器人:文本=注销>< /按钮>
< / LinearLayout中>
< / SlidingDrawer>
< / LinearLayout中>
< android.view.SurfaceView的xmlns:机器人=http://schemas.android.com/apk/res/android
机器人:ID =@ + ID / preVIEW
机器人:layout_width =FILL_PARENT
机器人:layout_height =FILL_PARENT
>
< /android.view.SurfaceView>
< / RelativeLayout的>
< /滚动型>
我有同样的问题,所以我去了挖源$ C $ C。最基本的答案是那个叫什么措施()
您SlidingDrawer使用 MeasureSpec.UNSPECIFIED
,即SlidingDrawer允许设置自己的大小。
这可能由含布局(或其父母)造成的是基础对齐或具有 WRAP_CONTENT
作为其高度或宽度。如果含有的LinearLayout具有 baselineAligned
设置为true,它要求所有的孩子为他们的大小,找到最大的一个。当然,这也要求它的孩子为他们的大小,如果它应该来包装他们。
设置安卓baselineAligned =假
在包含滑动抽屉,保证含SlidingDrawer,没有什么任何的LinearLayout有WRAP_CONTENT的高度或宽度。换句话说,在SlidingDrawer必须定义一个确切的尺寸,其家长也必须如果使用这意味着 FILL_PARENT
。
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
.
这篇关于SlidingDrawer不能有不定的尺寸的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!