Stay organized with collections
Save and categorize content based on your preferences.
public
static
final
class
InputDevice.ViewBehavior
extends Object
Provides information on how views processing MotionEvent
s generated by this input
device should respond to the events. Use InputManager.getInputDeviceViewBehavior(int)
to get an instance of the view behavior for an input device.
See an example below how a View
can use this class to determine and apply the
scrolling behavior for a generic 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...
}
Summary
Public methods |
boolean
|
shouldSmoothScroll(int axis, int source)
Returns whether a view should smooth scroll when scrolling due to a MotionEvent
generated by the input device.
|
Inherited methods |
From class
java.lang.Object
Object
|
clone()
Creates and returns a copy of this object.
|
boolean
|
equals(Object obj)
Indicates whether some other object is "equal to" this one.
|
void
|
finalize()
Called by the garbage collector on an object when garbage collection
determines that there are no more references to the object.
|
final
Class<?>
|
getClass()
Returns the runtime class of this Object .
|
int
|
hashCode()
Returns a hash code value for the object.
|
final
void
|
notify()
Wakes up a single thread that is waiting on this object's
monitor.
|
final
void
|
notifyAll()
Wakes up all threads that are waiting on this object's monitor.
|
String
|
toString()
Returns a string representation of the object.
|
final
void
|
wait(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
|
wait(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
|
wait()
Causes the current thread to wait until it is awakened, typically
by being notified or interrupted.
|
|
Public methods
public boolean shouldSmoothScroll (int axis,
int source)
Returns whether a view should smooth scroll when scrolling due to a 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 MotionRange
with the provided axis and
source, this method returns false
.
Parameters |
axis |
int : the MotionEvent axis whose value is used to get the scroll extent. |
source |
int : the InputDevice source from which the MotionEvent that
triggers the scroll came. |
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. |
Content and code samples on this page are subject to the licenses described in the Content License. Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.
Last updated 2025-02-10 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-02-10 UTC."],[],[],null,["# InputDevice.ViewBehavior\n\nAdded in [API level 35](/guide/topics/manifest/uses-sdk-element#ApiLevels) \nSummary: [Methods](#pubmethods) \\| [Inherited Methods](#inhmethods) \n\nInputDevice.ViewBehavior\n========================\n\n*** ** * ** ***\n\n[Kotlin](/reference/kotlin/android/view/InputDevice.ViewBehavior \"View this page in Kotlin\") \\|Java\n\n\n`\npublic\nstatic\nfinal\n\nclass\nInputDevice.ViewBehavior\n`\n\n\n`\n\nextends `[Object](/reference/java/lang/Object)`\n\n\n`\n\n`\n\n\n`\n\n|---|---------------------------------------|\n| [java.lang.Object](/reference/java/lang/Object) ||\n| ↳ | android.view.InputDevice.ViewBehavior |\n\n\u003cbr /\u003e\n\n*** ** * ** ***\n\nProvides information on how views processing [MotionEvent](/reference/android/view/MotionEvent)s generated by this input\ndevice should respond to the events. Use [InputManager.getInputDeviceViewBehavior(int)](/reference/android/hardware/input/InputManager#getInputDeviceViewBehavior(int))\nto get an instance of the view behavior for an input device.\n\nSee an example below how a [View](/reference/android/view/View) can use this class to determine and apply the\nscrolling behavior for a generic [MotionEvent](/reference/android/view/MotionEvent).\n\n public boolean onGenericMotionEvent(MotionEvent event) {\n InputManager manager = context.getSystemService(InputManager.class);\n ViewBehavior viewBehavior = manager.getInputDeviceViewBehavior(event.getDeviceId());\n // Assume a helper function that tells us which axis to use for scrolling purpose.\n int axis = getScrollAxisForGenericMotionEvent(event);\n int source = event.getSource();\n\n boolean shouldSmoothScroll =\n viewBehavior != null && viewBehavior.shouldSmoothScroll(axis, source);\n // Proceed to running the scrolling logic...\n }\n \n\u003cbr /\u003e\n\n**See also:**\n\n- [InputManager.getInputDeviceViewBehavior(int)](/reference/android/hardware/input/InputManager#getInputDeviceViewBehavior(int))\n\nSummary\n-------\n\n| ### Public methods ||\n|------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| ` boolean` | ` `[shouldSmoothScroll](/reference/android/view/InputDevice.ViewBehavior#shouldSmoothScroll(int,%20int))`(int axis, int source) ` Returns whether a view should smooth scroll when scrolling due to a [MotionEvent](/reference/android/view/MotionEvent) generated by the input device. |\n\n| ### Inherited methods |\n|-----------------------|---|\n| From class ` `[java.lang.Object](/reference/java/lang/Object)` ` |---------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](/reference/java/lang/Object) | ` `[clone](/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object. | | ` boolean` | ` `[equals](/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](/reference/java/lang/Object)` obj) ` Indicates whether some other object is \"equal to\" this one. | | ` void` | ` `[finalize](/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 `[Class](/reference/java/lang/Class)`\u003c?\u003e` | ` `[getClass](/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this `Object`. | | ` int` | ` `[hashCode](/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object. | | ` final void` | ` `[notify](/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor. | | ` final void` | ` `[notifyAll](/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor. | | ` `[String](/reference/java/lang/String) | ` `[toString](/reference/java/lang/Object#toString())`() ` Returns a string representation of the object. | | ` final void` | ` `[wait](/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` | ` `[wait](/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` | ` `[wait](/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being *notified* or *interrupted*. | ||\n\nPublic methods\n--------------\n\n### shouldSmoothScroll\n\nAdded in [API level 35](/guide/topics/manifest/uses-sdk-element#ApiLevels) \n\n```\npublic boolean shouldSmoothScroll (int axis, \n int source)\n```\n\nReturns whether a view should smooth scroll when scrolling due to a [MotionEvent](/reference/android/view/MotionEvent)\ngenerated by the input device.\n\nSmooth scroll in this case refers to a scroll that animates the transition between\nthe starting and ending positions of the scroll. When this method returns `true`,\nviews should try to animate a scroll generated by this device at the given axis and with\nthe given source to produce a good scroll user experience. If this method returns\n`false`, animating scrolls is not necessary.\n\nIf the input device does not have a [MotionRange](/reference/android/view/InputDevice.MotionRange) with the provided axis and\nsource, this method returns `false`.\n\n\u003cbr /\u003e\n\n| Parameters ||\n|----------|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `axis` | `int`: the [MotionEvent](/reference/android/view/MotionEvent) axis whose value is used to get the scroll extent. \u003cbr /\u003e |\n| `source` | `int`: the [InputDevice](/reference/android/view/InputDevice) source from which the [MotionEvent](/reference/android/view/MotionEvent) that triggers the scroll came. \u003cbr /\u003e |\n\n| Returns ||\n|-----------|---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|\n| `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. \u003cbr /\u003e |"]]