如何在Android视图中控制轨迹球行为?

如何在Android视图中控制轨迹球行为?,android,view,custom-controls,trackball,Android,View,Custom Controls,Trackball,我有一个FrameLayout视图,其中包含一个(类似MapView)控件和一些附加按钮。(布局xml如下所示) 我想让用户不仅可以使用触摸屏,还可以使用轨迹球来平移/滚动主视图。 问题是-使用轨迹球只是在布局上的所有控件之间切换焦点,我似乎找不到方法将onTrackballEvent仅包含在主视图中 欢迎提出任何建议,提前谢谢 <?xml version="1.0" encoding="utf-8"?> <merge xmlns:android="http://schema

我有一个FrameLayout视图,其中包含一个(类似MapView)控件和一些附加按钮。(布局xml如下所示)

我想让用户不仅可以使用触摸屏,还可以使用轨迹球来平移/滚动主视图。 问题是-使用轨迹球只是在布局上的所有控件之间切换焦点,我似乎找不到方法将onTrackballEvent仅包含在主视图中

欢迎提出任何建议,提前谢谢

<?xml version="1.0" encoding="utf-8"?>

<merge xmlns:android="http://schemas.android.com/apk/res/android"   
    android:layout_width="fill_parent" android:layout_height="fill_parent">
<FrameLayout android:id="@+id/pageView" 
    xmlns:panel="http://schemas.android.com/apk/res/com.yappa"
      xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="fill_parent"
  android:layout_height="fill_parent">

    <MainView
        android:id="@+id/mainView" 
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
    </MainView>


    <ZoomControls android:id="@+id/ZoomControls01"
        android:layout_gravity="bottom|center"
        android:layout_height="wrap_content" android:layout_width="wrap_content">
    </ZoomControls>

    <Panel
          ....
    </Panel>

</FrameLayout>

</merge>


诀窍是覆盖自定义视图中的
dispatchTrackball
,并获取事件


我希望这能对其他人有所帮助。

平移只需通过前面提到的focusable属性来实现,将mapview的focusable属性设置为true,当您将mapview置于焦点时,它确实会使用轨迹球平移地图。

嘿,reflog,我也处于同样的情况,可以给我一个示例代码吗?您是否尝试过使用android:focusable
属性?focusable控件如何从一个控件切换到另一个控件。不是我在问题中的意思