I am trying to add sliding drawer with scroll view but sliding drawer not working in scroll view, application collapse immediately showing error that scroll view can host only one child, i was unable to find out where is the error exactly and where to put sliding drawer in scroll view
please help me to resolve this issue
下面是我的android_main.xml代码,其中我将滚动视图作为所有元素的父容器,我无法在滚动视图中猜出滑动抽屉的确切位置,请帮我解决此问题。
提前谢谢
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true" >
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin" >
<LinearLayout
android:id="@+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<Spinner
android:id="@+id/City"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:weightSum="2" >
<Spinner
android:id="@+id/Cat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="[select]" />
<Spinner
android:id="@+id/subCat"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<EditText
android:id="@+id/edt_tweet"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="Classified"
android:inputType="textMultiLine"
android:maxLength="140"
android:textColor="@color/gray" >
</EditText>
<TextView
android:id="@+id/txt_Char"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:text="140 Characters remaining" />
<EditText
android:id="@+id/edt_dec"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:ems="10"
android:gravity="top"
android:hint="Description"
android:includeFontPadding="false"
android:inputType="textMultiLine"
android:minHeight="100dp"
android:textColor="@color/gray" />
<Spinner
android:id="@+id/spn_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1" />
<LinearLayout
android:id="@+id/image_Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:weightSum="3" >
<ImageView
android:id="@+id/PhotoView"
android:layout_width="match_parent"
android:layout_height="150dp"
android:layout_weight="2"
android:src="@drawable/ic_launcher" />
<LinearLayout
android:id="@+id/image_Layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:weightSum="1" >
<Button
android:id="@+id/btn_OK"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="OK" />
<Button
android:id="@+id/btn_Cancel"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Cancel" />
</LinearLayout>
</LinearLayout>
<EditText
android:id="@+id/edt_tags"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="Tags"
android:inputType="textMultiLine"
android:textColor="@color/gray" >
</EditText>
<EditText
android:id="@+id/edt_loc"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="Location"
android:inputType="textMultiLine"
android:textColor="@color/gray" >
</EditText>
<CheckBox
android:id="@+id/chk_loc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Show location on the map" />
<EditText
android:id="@+id/edt_contact"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:focusable="true"
android:hint="Contact on"
android:inputType="textMultiLine"
android:textColor="@color/gray" >
</EditText>
<CheckBox
android:id="@+id/chk_schedule"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Schedule Ad" />
<LinearLayout
android:id="@+id/lay_schedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:weightSum="2" >
<TextView
android:id="@+id/txt_choosedays"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Set Days" />
<TextView
android:id="@+id/txt_days"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentTop="true" />
<LinearLayout
android:id="@+id/lay_schedule"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="vertical"
android:paddingBottom="1dp"
android:paddingLeft="1dp"
android:paddingRight="1dp"
android:paddingTop="1dp" >
<TextView
android:id="@+id/txt_date"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Set Date" />
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:id="@+id/txt_frmdt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Date" />
<EditText
android:id="@+id/txt_frmSetDt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:editable="false"
android:hint="From" />
<TextView
android:id="@+id/txt_frmTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Time" />
<EditText
android:id="@+id/txt_frmSetTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:editable="false" />
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:weightSum="4" >
<TextView
android:id="@+id/txt_todt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Date" />
<EditText
android:id="@+id/txt_toSetDt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:editable="false"
android:hint="To" />
<TextView
android:id="@+id/txt_toTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="0.5"
android:text="Time" />
<EditText
android:id="@+id/txt_toSetTime"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1.5"
android:editable="false" />
</LinearLayout>
</LinearLayout>
</LinearLayout>
<View
android:layout_width="match_parent"
android:layout_height="2dp"
android:layout_alignParentTop="true" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:weightSum="3" >
<CheckBox
android:id="@+id/chk_pinned"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Pinned Ad" />
<CheckBox
android:id="@+id/chk_ticker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Ticker Ad" />
<CheckBox
android:id="@+id/chk_gallery"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Sponsered" />
</LinearLayout>
</LinearLayout>
</RelativeLayout>
<SlidingDrawer
android:id="@+id/Preview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:content="@+id/content"
android:allowSingleTap="true"
android:handle="@+id/handle" >
<Button
android:id="@+id/handle"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/ic_action_expand" />
<LinearLayout
android:id="@+id/content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:baselineAligned="false"
>
<Button
android:id="@+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="1"
/>
<Button
android:id="@+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="2" />
<Button
android:id="@+id/button3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="3" />
</LinearLayout>
</SlidingDrawer>
</ScrollView>
Below is the error log
11-10 13:23:30.794: E/AndroidRuntime(17864): FATAL EXCEPTION: main
11-10 13:23:30.794: E/AndroidRuntime(17864): java.lang.RuntimeException: Unable to start activity ComponentInfo{com.capstone.classitweetsdemo/com.capstone.classitweetsdemo.MainActivity}: java.lang.IllegalStateException: ScrollView can host only one direct child
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1967)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:1992)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.app.ActivityThread.access$600(ActivityThread.java:127)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1158)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.os.Handler.dispatchMessage(Handler.java:99)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.os.Looper.loop(Looper.java:137)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.app.ActivityThread.main(ActivityThread.java:4441)
11-10 13:23:30.794: E/AndroidRuntime(17864): at java.lang.reflect.Method.invokeNative(Native Method)
11-10 13:23:30.794: E/AndroidRuntime(17864): at java.lang.reflect.Method.invoke(Method.java:511)
11-10 13:23:30.794: E/AndroidRuntime(17864): at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:823)
11-10 13:23:30.794: E/AndroidRuntime(17864): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:590)
11-10 13:23:30.794: E/AndroidRuntime(17864): at dalvik.system.NativeStart.main(Native Method)
11-10 13:23:30.794: E/AndroidRuntime(17864): Caused by: java.lang.IllegalStateException: ScrollView can host only one direct child
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.widget.ScrollView.addView(ScrollView.java:241)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.view.LayoutInflater.rInflate(LayoutInflater.java:743)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.view.LayoutInflater.inflate(LayoutInflater.java:489)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.view.LayoutInflater.inflate(LayoutInflater.java:396)
11-10 13:23:30.794: E/AndroidRuntime(17864): at net.simonvt.menudrawer.MenuDrawer.setContentView(MenuDrawer.java:960)
11-10 13:23:30.794: E/AndroidRuntime(17864): at com.capstone.classitweetsdemo.MainActivity.onCreate(MainActivity.java:109)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.app.Activity.performCreate(Activity.java:4465)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1049)
11-10 13:23:30.794: E/AndroidRuntime(17864): at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:1931)
11-10 13:23:30.794: E/AndroidRuntime(17864): ... 11 more