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

时间:2009-05-27 14:16:39

标签: android view custom-controls trackball

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

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

欢迎任何建议,谢谢。

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

2 个答案:

答案 0 :(得分:1)

诀窍是覆盖自定义视图中的dispatchTrackball,然后抓住事件。

我希望这有助于某人。

答案 1 :(得分:0)

平移只是通过在focusable属性之前提到的实现,将mapview的focusable属性设置为true,当你将mapview放在焦点上时,它确实会用轨迹球平移地图。

相关问题