ViewConfiguration.getScaledTouchSlop () 用法

本文详细介绍了ViewConfiguration类的各种参数设置,包括触控响应时间、滑动距离阈值等关键配置,帮助开发者更好地理解并调整Android应用的用户交互体验。

ViewConfiguration.getScaledTouchSlop () 用法:

getScaledTouchSlop是一个距离,表示滑动的时候,手的移动要大于这个距离才开始移动控件。如果小于这个距离就不触发移动控件,如viewpager就是用这个距离来判断用户是否翻页

ViewConfiguration滑动参数设置类:

/**   
  * 包含了方法和标准的常量用来设置UI的超时、大小和距离   
  */
 public class ViewConfiguration {    
     // 设定水平滚动条的宽度和垂直滚动条的高度,单位是像素px    
     private static final int SCROLL_BAR_SIZE = 10;    
           
     //定义滚动条逐渐消失的时间,单位是毫秒    
     private static final int SCROLL_BAR_FADE_DURATION = 250;    
           
     // 默认的滚动条多少秒之后消失,单位是毫秒    
     private static final int SCROLL_BAR_DEFAULT_DELAY = 300;    
           
     // 定义边缘地方褪色的长度    
     private static final int FADING_EDGE_LENGTH = 12;    
           
     //定义子控件按下状态的持续事件    
     private static final int PRESSED_STATE_DURATION = 125;    
               
     //定义一个按下状态转变成长按状态的转变时间    
     private static final int LONG_PRESS_TIMEOUT = 500;    
               
     //定义用户在按住适当按钮,弹出全局的对话框的持续时间    
     private static final int GLOBAL_ACTIONS_KEY_TIMEOUT = 500;    
               
     //定义一个touch事件中是点击事件还是一个滑动事件所需的时间,如果用户在这个时间之内滑动,那么就认为是一个点击事件    
     private static final int TAP_TIMEOUT = 115;    
               
     /**   
      * Defines the duration in milliseconds we will wait to see if a touch event    
      * is a jump tap. If the user does not complete the jump tap within this interval, it is   
      * considered to be a tap.    
      */
     //定义一个touch事件时候是一个点击事件。如果用户在这个时间内没有完成这个点击,那么就认为是一个点击事件    
     private static final int JUMP_TAP_TIMEOUT = 500;    
           
     //定义双击事件的间隔时间    
     private static final int DOUBLE_TAP_TIMEOUT = 300;    
               
     //定义一个缩放控制反馈到用户界面的时间    
     private static final int ZOOM_CONTROLS_TIMEOUT = 3000;    
           
     /**   
      * Inset in pixels to look for touchable content when the user touches the edge of the screen   
      */
     private static final int EDGE_SLOP = 12;    
               
     /**   
      * Distance a touch can wander before we think the user is scrolling in pixels   
      */
     private static final int TOUCH_SLOP = 16;    
               
     /**   
      * Distance a touch can wander before we think the user is attempting a paged scroll   
      * (in dips)   
      */
     private static final int PAGING_TOUCH_SLOP = TOUCH_SLOP * 2;    
               
     /**   
      * Distance between the first touch and second touch to still be considered a double tap   
      */
     private static final int DOUBLE_TAP_SLOP = 100;    
               
     /**   
      * Distance a touch needs to be outside of a window's bounds for it to   
      * count as outside for purposes of dismissing the window.   
      */
     private static final int WINDOW_TOUCH_SLOP = 16;    
           
    //用来初始化fling的最小速度,单位是每秒多少像素    
     private static final int MINIMUM_FLING_VELOCITY = 50;    
               
     //用来初始化fling的最大速度,单位是每秒多少像素    
     private static final int MAXIMUM_FLING_VELOCITY = 4000;    
           
     //视图绘图缓存的最大尺寸,以字节表示。在ARGB888格式下,这个尺寸应至少等于屏幕的大小    
     @Deprecated    
     private static final int MAXIMUM_DRAWING_CACHE_SIZE = 320 * 480 * 4; // HVGA screen, ARGB8888    
           
     //flings和scrolls摩擦力度大小的系数    
     private static float SCROLL_FRICTION = 0.015f;    
           
     /**   
      * Max distance to over scroll for edge effects   
      */
     private static final int OVERSCROLL_DISTANCE = 0;    
           
     /**   
      * Max distance to over fling for edge effects   
      */
     private static final int OVERFLING_DISTANCE = 4;    
           
 }




2025-09-11 15:26:23.339 12036-12036 StrictMode com.android.camera2 E Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.android.camera.app.CameraApp@27d9b32 The API:ViewConfiguration needs a proper configuration. Use UI contexts such as an activity or a context created via createWindowContext(Display, int, Bundle) or createConfigurationContext(Configuration) with a proper configuration. java.lang.IllegalAccessException: Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.android.camera.app.CameraApp@27d9b32 at android.os.StrictMode.assertConfigurationContext(StrictMode.java:2295) at android.view.ViewConfiguration.get(ViewConfiguration.java:526) at android.view.GestureDetector.init(GestureDetector.java:473) at android.view.GestureDetector.<init>(GestureDetector.java:432) at android.view.GestureDetector.<init>(GestureDetector.java:400) at com.android.camera.app.CameraAppUI.<init>(CameraAppUI.java:918) at com.android.camera.CameraActivity.onCreateTasks(CameraActivity.java:1755) at com.android.camera.util.QuickActivity.onCreate(QuickActivity.java:114) at android.app.Activity.performCreate(Activity.java:8357) at android.app.Activity.performCreate(Activity.java:8336) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7924) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
09-12
2025-07-06 16:25:10.644 936-936 ViewConfiguration com.android.launcher3 E Tried to access UI constants from a non-visual Context:com.android.quickstep.inputconsumers.OtherActivityInputConsumer@d0ca171UI constants, such as display metrics or window metrics, must be accessed from Activity or other visual Context. Use an Activity or a Context created with Context#createWindowContext(int, Bundle), which are adjusted to the configuration and visual bounds of an area on screen java.lang.IllegalArgumentException: Tried to access UI constants from a non-visual Context:com.android.quickstep.inputconsumers.OtherActivityInputConsumer@d0ca171 at android.view.ViewConfiguration.get(ViewConfiguration.java:510) at com.android.quickstep.inputconsumers.OtherActivityInputConsumer.<init>(OtherActivityInputConsumer.java:163) at com.android.quickstep.TouchInteractionService.createOtherActivityInputConsumer(TouchInteractionService.java:709) at com.android.quickstep.TouchInteractionService.newBaseConsumer(TouchInteractionService.java:692) at com.android.quickstep.TouchInteractionService.newConsumer(TouchInteractionService.java:587) at com.android.quickstep.TouchInteractionService.onInputEvent(TouchInteractionService.java:493) at com.android.quickstep.TouchInteractionService.lambda$5N8OpQhfWV7_tkhenf8Ys3ECXWs(Unknown Source:0) at com.android.quickstep.-$$Lambda$TouchInteractionService$5N8OpQhfWV7_tkhenf8Ys3ECXWs.onInputEvent(Unknown Source:2) at com.android.systemui.shared.system.InputChannelCompat$InputEventReceiver$1.onInputEvent(InputChannelCompat.java:81) at android.view.InputEventReceiver.dispatchInputEvent(InputEventReceiver.java:220) at android.os.MessageQueue.nativePollOnce(Native Method) at android.os.MessageQueue.next(MessageQueue.java:335) at android.os.Looper.loop(Looper.java:183) at android.app.ActivityThread.main(ActivityThread.java:7660) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:592)
07-07
2025-09-11 15:26:23.338 12036-12036 StrictMode com.android.camera2 E Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.android.camera.app.CameraApp@27d9b32 The API:ViewConfiguration needs a proper configuration. Use UI contexts such as an activity or a context created via createWindowContext(Display, int, Bundle) or createConfigurationContext(Configuration) with a proper configuration. java.lang.IllegalAccessException: Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.android.camera.app.CameraApp@27d9b32 at android.os.StrictMode.assertConfigurationContext(StrictMode.java:2295) at android.view.ViewConfiguration.get(ViewConfiguration.java:526) at com.android.camera.app.CameraAppUI.<init>(CameraAppUI.java:906) at com.android.camera.CameraActivity.onCreateTasks(CameraActivity.java:1755) at com.android.camera.util.QuickActivity.onCreate(QuickActivity.java:114) at android.app.Activity.performCreate(Activity.java:8357) at android.app.Activity.performCreate(Activity.java:8336) at android.app.Instrumentation.callActivityOnCreate(Instrumentation.java:1417) at android.app.ActivityThread.performLaunchActivity(ActivityThread.java:3626) at android.app.ActivityThread.handleLaunchActivity(ActivityThread.java:3782) at android.app.servertransaction.LaunchActivityItem.execute(LaunchActivityItem.java:101) at android.app.servertransaction.TransactionExecutor.executeCallbacks(TransactionExecutor.java:138) at android.app.servertransaction.TransactionExecutor.execute(TransactionExecutor.java:95) at android.app.ActivityThread$H.handleMessage(ActivityThread.java:2307) at android.os.Handler.dispatchMessage(Handler.java:106) at android.os.Looper.loopOnce(Looper.java:201) at android.os.Looper.loop(Looper.java:288) at android.app.ActivityThread.main(ActivityThread.java:7924) at java.lang.reflect.Method.invoke(Native Method) at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:936)
最新发布
09-12
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值