【问题标题】:How to control trackball behaviour in Android Views?如何控制 Android 视图中的轨迹球行为?
【发布时间】:2010-10-29 07:03:24
【问题描述】:

我有一个 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>

【问题讨论】:

  • 您尝试过使用android:focusable 属性吗?
  • focusable 控制您如何从一个控件转到另一个控件。不是我在问题中的意思

标签: android view custom-controls trackball


【解决方案1】:

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

我希望这对某人有所帮助。

【讨论】:

  • 你好reflog,我也有同样的情况,能给我一个示例代码吗?
【解决方案2】:

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

【讨论】:

    猜你喜欢
    • 2012-12-17
    • 1970-01-01
    • 2012-10-02
    • 2015-04-18
    • 1970-01-01
    • 1970-01-01
    • 2013-11-24
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多