Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels) Summary: [Methods](https://developer.android.com/reference/android/view/InputDevice.ViewBehavior#pubmethods) \| [Inherited Methods](https://developer.android.com/reference/android/view/InputDevice.ViewBehavior#inhmethods)

# InputDevice.ViewBehavior

*** ** * ** ***


`
public
static
final

class
InputDevice.ViewBehavior
`


`

extends https://developer.android.com/reference/java/lang/Object


`

`


`

|---|---|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | android.view.InputDevice.ViewBehavior |

<br />

*** ** * ** ***

Provides information on how views processing `https://developer.android.com/reference/android/view/MotionEvent`s generated by this input
device should respond to the events. Use `https://developer.android.com/reference/android/hardware/input/InputManager#getInputDeviceViewBehavior(int)`
to get an instance of the view behavior for an input device.

See an example below how a `https://developer.android.com/reference/android/view/View` can use this class to determine and apply the
scrolling behavior for a generic `https://developer.android.com/reference/android/view/MotionEvent`.

    public boolean onGenericMotionEvent(MotionEvent event) {
            InputManager manager = context.getSystemService(InputManager.class);
            ViewBehavior viewBehavior = manager.getInputDeviceViewBehavior(event.getDeviceId());
            // Assume a helper function that tells us which axis to use for scrolling purpose.
            int axis = getScrollAxisForGenericMotionEvent(event);
            int source = event.getSource();

            boolean shouldSmoothScroll =
                    viewBehavior != null && viewBehavior.shouldSmoothScroll(axis, source);
            // Proceed to running the scrolling logic...
        }

<br />

**See also:**

- `https://developer.android.com/reference/android/hardware/input/InputManager#getInputDeviceViewBehavior(int)`

## Summary

| ### Public methods ||
|---|---|
| ` int` | ` https://developer.android.com/reference/android/view/InputDevice.ViewBehavior#getPrimaryDirectionalMotionAxis()() ` Returns the primary directional motion axis for the input device, described as one of the `https://developer.android.com/reference/android/view/MotionEvent` axes. |
| ` boolean` | ` https://developer.android.com/reference/android/view/InputDevice.ViewBehavior#hasPrimaryDirectionalMotionAxis()() ` Whether the input device has a primary directional motion axis. |
| ` boolean` | ` https://developer.android.com/reference/android/view/InputDevice.ViewBehavior#shouldSmoothScroll(int,%20int)(int axis, int source) ` Returns whether a view should smooth scroll when scrolling due to a `https://developer.android.com/reference/android/view/MotionEvent` generated by the input device. |

### Inherited methods

From class `

https://developer.android.com/reference/java/lang/Object

` `


https://developer.android.com/reference/java/lang/Object` `
https://developer.android.com/reference/java/lang/Object#clone()()
`

Creates and returns a copy of this object.


`


boolean` `
https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object)(https://developer.android.com/reference/java/lang/Object obj)
`

Indicates whether some other object is "equal to" this one.


`


void` `
https://developer.android.com/reference/java/lang/Object#finalize()()
`

Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.


`


final

https://developer.android.com/reference/java/lang/Class<?>` `
https://developer.android.com/reference/java/lang/Object#getClass()()
`

Returns the runtime class of this `Object`.


`


int` `
https://developer.android.com/reference/java/lang/Object#hashCode()()
`

Returns a hash code value for the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notify()()
`

Wakes up a single thread that is waiting on this object's
monitor.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#notifyAll()()
`

Wakes up all threads that are waiting on this object's monitor.


`


https://developer.android.com/reference/java/lang/String` `
https://developer.android.com/reference/java/lang/Object#toString()()
`

Returns a string representation of the object.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long,%20int)(long timeoutMillis, int nanos)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait(long)(long timeoutMillis)
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*, or until a
certain amount of real time has elapsed.


`


final

void` `
https://developer.android.com/reference/java/lang/Object#wait()()
`

Causes the current thread to wait until it is awakened, typically
by being *notified* or *interrupted*.


## Public methods

### getPrimaryDirectionalMotionAxis

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public int getPrimaryDirectionalMotionAxis ()
```

Returns the primary directional motion axis for the input device, described as one of the
`https://developer.android.com/reference/android/view/MotionEvent` axes.

When specified, the primary directional motion axis is the axis that should be
preferred for gesture handling in one dimension, like flings or swipes, even if there are
other axes available. For example, a touchpad with a Y axis that is physically much
larger from the X axis can specify that the Y axis is the primary directional motion
axis, and therefore gestures should be interpreted along the Y axis, even though an X
axis also exists.

If the input device does not have a primary directional motion axis, this method will
throw an `https://developer.android.com/reference/java/lang/IllegalStateException`, so this method should only be called if `https://developer.android.com/reference/android/view/InputDevice.ViewBehavior#hasPrimaryDirectionalMotionAxis()` returns `true`.

<br />

| Returns ||
|---|---|
| `int` | the primary directional motion axis given as one of the `https://developer.android.com/` constants. Value is one of the following: - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_X` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_Y` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_PRESSURE` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_SIZE` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOUCH_MAJOR` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOUCH_MINOR` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOOL_MAJOR` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_TOOL_MINOR` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_ORIENTATION` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_VSCROLL` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_HSCROLL` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_Z` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_RX` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_RY` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_RZ` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_HAT_X` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_HAT_Y` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_LTRIGGER` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_RTRIGGER` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_THROTTLE` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_RUDDER` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_WHEEL` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GAS` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_BRAKE` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_DISTANCE` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_TILT` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_SCROLL` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_RELATIVE_X` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_RELATIVE_Y` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_1` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_2` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_3` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_4` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_5` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_6` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_7` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_8` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_9` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_10` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_11` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_12` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_13` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_14` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_15` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GENERIC_16` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GESTURE_X_OFFSET` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GESTURE_Y_OFFSET` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GESTURE_SCROLL_X_DISTANCE` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GESTURE_SCROLL_Y_DISTANCE` - `https://developer.android.com/reference/android/view/MotionEvent#AXIS_GESTURE_PINCH_SCALE_FACTOR` |

| Throws ||
|---|---|
| `https://developer.android.com/reference/java/lang/IllegalStateException` | if the input device does not have a primary directional motion axis (i.e., `https://developer.android.com/reference/android/view/InputDevice.ViewBehavior#hasPrimaryDirectionalMotionAxis()` returns `false`). |

### hasPrimaryDirectionalMotionAxis

Added in [version 37.2](https://developer.android.com/topic/libraries/support-library/revisions)

```
public boolean hasPrimaryDirectionalMotionAxis ()
```

Whether the input device has a primary directional motion axis.

<br />

| Returns ||
|---|---|
| `boolean` | `true` if the input device has a primary directional motion axis, or `false` otherwise. <br /> |

### shouldSmoothScroll

Added in [API level 35](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)

```
public boolean shouldSmoothScroll (int axis, 
                int source)
```

Returns whether a view should smooth scroll when scrolling due to a `https://developer.android.com/reference/android/view/MotionEvent`
generated by the input device.

Smooth scroll in this case refers to a scroll that animates the transition between
the starting and ending positions of the scroll. When this method returns `true`,
views should try to animate a scroll generated by this device at the given axis and with
the given source to produce a good scroll user experience. If this method returns
`false`, animating scrolls is not necessary.

If the input device does not have a `https://developer.android.com/reference/android/view/InputDevice.MotionRange` with the provided axis and
source, this method returns `false`.

<br />

| Parameters ||
|---|---|
| `axis` | `int`: the `https://developer.android.com/reference/android/view/MotionEvent` axis whose value is used to get the scroll extent. <br /> |
| `source` | `int`: the `https://developer.android.com/reference/android/view/InputDevice` source from which the `https://developer.android.com/reference/android/view/MotionEvent` that triggers the scroll came. <br /> |

| Returns ||
|---|---|
| `boolean` | `true` if smooth scrolling should be used for the scroll, or `false` if smooth scrolling is not necessary, or if the provided axis and source combination is not available for the input device. <br /> |