reflog
reflog

Reputation: 7645

How to control trackball behaviour in Android Views?

I have a FrameLayout view which contains one (MapView-like) control and some additional buttons overlaying it. (the layout xml is below).

I want to allow the user to pan/scroll the main view using not only touch but also the Trackball. The problem is - using the trackball just switches the focus between all the controls on the layout, and I cannot seem to find a way to contain the onTrackballEvent to just the MainView.

Any suggestions are welcome, thanks in advance.

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

Upvotes: 0

Views: 2899

Answers (2)

reflog
reflog

Reputation: 7645

The trick is to override the dispatchTrackball in your custom view, and grab the events.

I hope this helps someone.

Upvotes: 1

user756212
user756212

Reputation: 522

Panning is simply implemented by as mentioned before the focusable property, set your mapview's focusable attribute to true and it will indeed pan the map with the trackball when you have placed the mapview in focus.

Upvotes: 0

Related Questions