Android ViewConfiguration.getScaledTouchSlop () 用法

在写下拉刷新的时候,遇到这个参数touchSlop= ViewConfiguration.get(context).getScaledTouchSlop(),它表示在被判定为滚动之前用户手指可以移动的最大值。然后特意查了一下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;     
           
 }


01-01 08:11:27.038 E/StrictMode( 2641): Tried to access the API:ViewConfiguration which needs to have proper configuration from a non-UI Context:com.android.camera.app.CameraApp@32d9eff 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. 01-01 08:11:27.038 E/StrictMode( 2641): 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@32d9eff 01-01 08:11:27.038 E/StrictMode( 2641): at android.os.StrictMode.assertConfigurationContext(StrictMode.java:2296) 01-01 08:11:27.038 E/StrictMode( 2641): at android.view.ViewConfiguration.get(ViewConfiguration.java:521) 01-01 08:11:27.038 E/StrictMode( 2641): at android.view.View.<init>(View.java:5321) 01-01 08:11:27.038 E/StrictMode( 2641): at android.widget.ImageView.<init>(ImageView.java:181) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.data.PhotoItem.getView(PhotoItem.java:127) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.data.CameraFilmstripDataAdapter.getView(CameraFilmstripDataAdapter.java:151) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.widget.FilmstripView.buildViewItemAt(FilmstripView.java:850) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.widget.FilmstripView.reload(FilmstripView.java:1827) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.widget.FilmstripView.access$1300(FilmstripView.java:58) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.widget.FilmstripView$3.onFilmstripItemLoaded(FilmstripView.java:1567) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.data.CameraFilmstripDataAdapter.replaceItemList(CameraFilmstripDataAdapter.java:276) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.data.CameraFilmstripDataAdapter.access$700(CameraFilmstripDataAdapter.java:39) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.data.CameraFilmstripDataAdapter$QueryTask.onPostExecute(CameraFilmstripDataAdapter.java:447) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.camera.data.CameraFilmstripDataAdapter$QueryTask.onPostExecute(CameraFilmstripDataAdapter.java:379) 01-01 08:11:27.038 E/StrictMode( 2641): at android.os.AsyncTask.finish(AsyncTask.java:771) 01-01 08:11:27.038 E/StrictMode( 2641): at android.os.AsyncTask.access$900(AsyncTask.java:199) 01-01 08:11:27.038 E/StrictMode( 2641): at android.os.AsyncTask$InternalHandler.handleMessage(AsyncTask.java:788) 01-01 08:11:27.038 E/StrictMode( 2641): at android.os.Handler.dispatchMessage(Handler.java:106) 01-01 08:11:27.038 E/StrictMode( 2641): at android.os.Looper.loopOnce(Looper.java:201) 01-01 08:11:27.038 E/StrictMode( 2641): at android.os.Looper.loop(Looper.java:288) 01-01 08:11:27.038 E/StrictMode( 2641): at android.app.ActivityThread.main(ActivityThread.java:7870) 01-01 08:11:27.038 E/StrictMode( 2641): at java.lang.reflect.Method.invoke(Native Method) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.internal.os.RuntimeInit$MethodAndArgsCaller.run(RuntimeInit.java:548) 01-01 08:11:27.038 E/StrictMode( 2641): at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:1003)
最新发布
07-14
根据报错信息,可以看出问题是在相机应用中使用了非 UI 上下文(non-UI Context)来访问 ViewConfiguration API,导致了 IllegalAccessException 异常。 这个错误可能是由于相机应用在非 UI 上下文中尝试访问 UI 相关的 API 导致的。UI 相关的操作通常需要在活动(Activity)或以正确配置创建的上下文中进行,而不是在后台线程或其他非 UI 上下文中。 为了解决这个问题,你可以尝试以下几个方法: 1. 确保在相机应用中的任何操作都在正确的 UI 上下文中进行。如果你在后台线程中执行操作,确保正确地切换到主线程来执行与 UI 相关的操作。 2. 检查相机应用的代码,确保没有在非 UI 上下文中访问 UI 相关的 API。检查是否有在异步任务(AsyncTask)或其他后台线程中执行的代码尝试访问 UI 相关的 API。 3. 如果你无法确定问题出在哪个部分,可以尝试使用调试工具(如 Android Studio)对相机应用进行调试,并观察在哪个代码段出现了异常。 4. 如果你是相机应用的开发者,可以参考 Android 文档和开发者指南,了解如何正确处理 UI 相关的操作和上下文。确保在正确的上下文中执行 UI 操作,或者使用合适的方法传递正确的上下文。 5. 如果你是应用的用户,尝试卸载并重新安装相机应用,或者尝试使用其他相机应用作为替代。 请注意,具体解决方法可能因相机应用的实现方式和代码结构而有所差异。如果问题仍然存在,你可能需要向相机应用的开发者寻求更具体的帮助和支持。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值