我从我正在使用的自定义UI组件类引发的RuntimeException
引起了一些异常报告。以下是代码(此代码归功于this post):
public class WrapingSlidingDrawer extends SlidingDrawer {
public WrapingSlidingDrawer(Context context, AttributeSet attrs, int defStyle)
{
super(context, attrs, defStyle);
int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}
public WrapingSlidingDrawer(Context context, AttributeSet attrs)
{
super(context, attrs);
int orientation = attrs.getAttributeIntValue("android", "orientation", ORIENTATION_VERTICAL);
mTopOffset = attrs.getAttributeIntValue("android", "topOffset", 0);
mVertical = (orientation == SlidingDrawer.ORIENTATION_VERTICAL);
}
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec)
{
int widthSpecMode = MeasureSpec.getMode(widthMeasureSpec);
int widthSpecSize = MeasureSpec.getSize(widthMeasureSpec);
int heightSpecMode = MeasureSpec.getMode(heightMeasureSpec);
int heightSpecSize = MeasureSpec.getSize(heightMeasureSpec);
if (widthSpecMode == MeasureSpec.UNSPECIFIED || heightSpecMode == MeasureSpec.UNSPECIFIED)
{
throw new RuntimeException("SlidingDrawer cannot have UNSPECIFIED dimensions");
}
这是我正在使用的声明性XML:
<RelativeLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/customDrawerLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignParentBottom="true">
<com.package.WrapingSlidingDrawer
android:id="@+id/slidingDrawer"
android:handle="@+id/Handle"
android:content="@+id/contentLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true">
自定义滑动抽屉和父级都指定了布局宽度和高度属性。因此,任何关于什么可能导致缺陷出现的想法?它很少发生。