2

您如何将拉出式菜单创建为新的Activity.

是否有可能像谷歌内置的摄像机应用程序那样有一个可以拉出的按钮并开始一个新的活动?

按钮支持拔出吗?如果不是,那是什么?

4

2 回答 2

2

请参阅更新 2 以获得最佳解决方案!

我想我也有同样的问题。为了更好地理解,我在这里用图片描述了它。我希望你们能为我和Namratha提供一些帮助......

替代文字

(哦,我刚刚注意到,ImageUploader 弄乱了我在图片中的文字。它应该说“我想在我的应用程序中构建一个下拉菜单。它应该像这个例子一样工作。”)

更新

感谢 Janusz,他告诉我应该寻找什么。

出于某种原因,我的 Eclipse 布局预览中总是出现此错误:

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)

那是布局xml。我刚刚删除了可绘制资源指针......

<?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>

更新 2

刚刚注意到,对我来说有一个更好的解决方案。因为SlidingDrawer Widget 只支持从下往上滑动。我第一次更新的错误仍然存​​在。

于 2010-11-01T08:43:01.203 回答
0

用于这种布局的小部件是一个滑动抽屉。您只需为手柄定义​​一个布局,为抽屉的内容定义一个布局。现在您可以收听一些事件,例如抽屉被打开、滚动或关闭。

于 2010-11-01T09:39:39.720 回答