开发者

How to create a pull out menu as a new Activity

How do you create a pull out menu as a new Activity.

Is it possible to have a button that you can pull out as in the Google's built in camcorder app and have that start a new activity?

Does a but开发者_如何学Cton support pull out? If not, what does?


See Update 2 for best solution!

I guess I have the same problem. For better understanding, I described it here in a picture. I hope u guys can provide Namratha and me some help...

How to create a pull out menu as a new Activity

(Oh I just noticed, the ImageUploader messed up my writing in the picture. It shall say "I'd like to build a drop down menu into my app. It should work just like this example.")

Udpate

Thanks to Janusz, who told me what I should look for.

For some reason I always get this error in my Eclipse Layout Preview:

java.lang.IllegalArgumentException: The handle attribute is required and must refer to a valid child.
    at android.widget.SlidingDrawer.<init>(SlidingDrawer.java:204)
    at android.widget.SlidingDrawer.<init>(SlidingDrawer.java:181)
    at sun.reflect.GeneratedConstructorAccessor204.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:27)
    at java.lang.reflect.Constructor.newInstance(Constructor.java:513)
    at android.view.LayoutInflater.createView(LayoutInflater.java:499)
    at android.view.BridgeInflater.onCreateView(BridgeInflater.java:77)
    at android.view.LayoutInflater.createViewFromTag(LayoutInflater.java:562)
    at android.view.BridgeInflater.createViewFromTag(BridgeInflater.java:122)
    at android.view.LayoutInflater.rInflate(LayoutInflater.java:617)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:407)
    at android.view.LayoutInflater.inflate(LayoutInflater.java:296)
    at com.android.layoutlib.bridge.Bridge.computeLayout(Bridge.java:377)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle1.GraphicalLayoutEditor.computeLayout(Unknown Source)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle1.GraphicalLayoutEditor.recomputeLayout(Unknown Source)
    at com.android.ide.eclipse.adt.internal.editors.layout.gle1.GraphicalLayoutEditor.activated(Unknown Source)
    at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.pageChange(Unknown Source)
    at org.eclipse.ui.part.MultiPageEditorPart$2.widgetSelected(MultiPageEditorPart.java:290)
    at org.eclipse.swt.widgets.TypedListener.handleEvent(TypedListener.java:234)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3776)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1367)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1390)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1375)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1187)
    at org.eclipse.swt.custom.CTabFolder.setSelection(CTabFolder.java:2743)
    at org.eclipse.swt.custom.CTabFolder.destroyItem(CTabFolder.java:500)
    at org.eclipse.swt.custom.CTabItem.dispose(CTabItem.java:126)
    at org.eclipse.ui.part.MultiPageEditorPart.removePage(MultiPageEditorPart.java:1039)
    at org.eclipse.ui.forms.editor.FormEditor.removePage(FormEditor.java:368)
    at com.android.ide.eclipse.adt.internal.editors.layout.LayoutEditor.showEditorInput(Unknown Source)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditorBatched(WorkbenchPage.java:2847)
    at org.eclipse.ui.internal.WorkbenchPage.busyOpenEditor(WorkbenchPage.java:2768)
    at org.eclipse.ui.internal.WorkbenchPage.access$11(WorkbenchPage.java:2760)
    at org.eclipse.ui.internal.WorkbenchPage$10.run(WorkbenchPage.java:2711)
    at org.eclipse.swt.custom.BusyIndicator.showWhile(BusyIndicator.java:70)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2707)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2691)
    at org.eclipse.ui.internal.WorkbenchPage.openEditor(WorkbenchPage.java:2682)
    at org.eclipse.ui.ide.IDE.openEditor(IDE.java:651)
    at org.eclipse.ui.ide.IDE.openEditor(IDE.java:610)
    at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:365)
    at org.eclipse.jdt.internal.ui.javaeditor.EditorUtility.openInEditor(EditorUtility.java:168)
    at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:229)
    at org.eclipse.jdt.ui.actions.OpenAction.run(OpenAction.java:208)
    at org.eclipse.jdt.ui.actions.SelectionDispatchAction.dispatchRun(SelectionDispatchAction.java:274)
    at org.eclipse.jdt.ui.actions.SelectionDispatchAction.run(SelectionDispatchAction.java:250)
    at org.eclipse.jdt.internal.ui.navigator.OpenAndExpand.run(OpenAndExpand.java:49)
    at org.eclipse.ui.actions.RetargetAction.run(RetargetAction.java:221)
    at org.eclipse.ui.navigator.CommonNavigatorManager$3.open(CommonNavigatorManager.java:185)
    at org.eclipse.ui.OpenAndLinkWithEditorHelper$InternalListener.open(OpenAndLinkWithEditorHelper.java:48)
    at org.eclipse.jface.viewers.StructuredViewer$2.run(StructuredViewer.java:845)
    at org.eclipse.core.runtime.SafeRunner.run(SafeRunner.java:42)
    at org.eclipse.ui.internal.JFaceUtil$1.run(JFaceUtil.java:49)
    at org.eclipse.jface.util.SafeRunnable.run(SafeRunnable.java:175)
    at org.eclipse.jface.viewers.StructuredViewer.fireOpen(StructuredViewer.java:843)
    at org.eclipse.jface.viewers.StructuredViewer.handleOpen(StructuredViewer.java:1131)
    at org.eclipse.ui.navigator.CommonViewer.handleOpen(CommonViewer.java:462)
    at org.eclipse.jface.viewers.StructuredViewer$6.handleOpen(StructuredViewer.java:1235)
    at org.eclipse.jface.util.OpenStrategy.fireOpenEvent(OpenStrategy.java:264)
    at org.eclipse.jface.util.OpenStrategy.access$2(OpenStrategy.java:258)
    at org.eclipse.jface.util.OpenStrategy$1.handleEvent(OpenStrategy.java:298)
    at org.eclipse.swt.widgets.EventTable.sendEvent(EventTable.java:84)
    at org.eclipse.swt.widgets.Display.sendEvent(Display.java:3776)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1367)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1390)
    at org.eclipse.swt.widgets.Widget.sendEvent(Widget.java:1375)
    at org.eclipse.swt.widgets.Widget.notifyListeners(Widget.java:1187)
    at org.eclipse.swt.widgets.Display.runDeferredEvents(Display.java:3622)
    at org.eclipse.swt.widgets.Display.readAndDispatch(Display.java:3277)
    at org.eclipse.ui.internal.Workbench.runEventLoop(Workbench.java:2629)
    at org.eclipse.ui.internal.Workbench.runUI(Workbench.java:2593)
    at org.eclipse.ui.internal.Workbench.access$4(Workbench.java:2427)
    at org.eclipse.ui.internal.Workbench$7.run(Workbench.java:670)
    at org.eclipse.core.databinding.observable.Realm.runWithDefault(Realm.java:332)
    at org.eclipse.ui.internal.Workbench.createAndRunWorkbench(Workbench.java:663)
    at org.eclipse.ui.PlatformUI.createAndRunWorkbench(PlatformUI.java:149)
    at org.eclipse.ui.internal.ide.application.IDEApplication.start(IDEApplication.java:115)
    at org.eclipse.equinox.internal.app.EclipseAppHandle.run(EclipseAppHandle.java:196)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.runApplication(EclipseAppLauncher.java:110)
    at org.eclipse.core.runtime.internal.adaptor.EclipseAppLauncher.start(EclipseAppLauncher.java:79)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:369)
    at org.eclipse.core.runtime.adaptor.EclipseStarter.run(EclipseStarter.java:179)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)
    at java.lang.reflect.Method.invoke(Method.java:597)
    at org.eclipse.equinox.launcher.Main.invokeFramework(Main.java:619)
    at org.eclipse.equinox.launcher.Main.basicRun(Main.java:574)
    at org.eclipse.equinox.launcher.Main.run(Main.java:1407)

That'S the layout xml. I just removed the drawable resource pointers...

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:id="@+id/LinearLayoutTesting"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent"
  android:orientation="vertical"
  android:gravity="bottom">
  <SlidingDrawer
    android:layout_width="wrap_content"
    android:id="@+id/SlidingDrawer"
    android:handle="@+id/slideHandleButton"
    android:content="@+id/contentLayout"
    android:padding="10dip"
    android:layout_height="250dip">
    <Button
      android:layout_width="wrap_content"
      android:layout_height="wrap_content"
      android:id="@+id/slideHandleButton"></Button>
    <LinearLayout
      android:layout_width="wrap_content"
      android:id="@+id/contentLayout"
      android:orientation="vertical"
      android:gravity="center|top"
      android:padding="10dip"
      android:background="#C0C0C0"
      android:layout_height="wrap_content">
      <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Content"></Button>
      <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Content"></Button>
      <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Content"></Button>
    </LinearLayout>

  </SlidingDrawer>

</LinearLayout>

Update 2

Just noticed, there is a better solution for me. Because the SlidingDrawer Widget only supports sliding from bottom to the top. The error from my first Update is still existing.


The widget used for this kind of Layout is a Sliding Drawer. You just have to define a layout for the handle and one for the content of the drawer. Now you can listen to some events like the drawer was opened, scrolled or closed.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜