ViewConfiguration类的使用

本文详细介绍了ViewConfiguration类的作用及实现方式,特别聚焦于getScaledTouchSlop()方法的应用,该方法用于确定用户何时开始滚动的触控偏移阈值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ViewConfiguration包含方法用于超时,UI标准常数的大小,和距离。

个人感觉类似于常量类,都是和UI有关的

在实际开发过程中用到了这个方法:

ViewConfiguration.get(context).getScaledTouchSlop();这个方法返回的是一个常量值,我这块用到这个方法是用来根据这个距离判断移动状态。

public class ViewConfiguration {


private final int mTouchSlop;

private static final int TOUCH_SLOP = 8;

public ViewConfiguration() {
        mEdgeSlop = EDGE_SLOP;
        mFadingEdgeLength = FADING_EDGE_LENGTH;
        mMinimumFlingVelocity = MINIMUM_FLING_VELOCITY;
        mMaximumFlingVelocity = MAXIMUM_FLING_VELOCITY;
        mScrollbarSize = SCROLL_BAR_SIZE;
        mTouchSlop = TOUCH_SLOP;
        mDoubleTapTouchSlop = DOUBLE_TAP_TOUCH_SLOP;
        mPagingTouchSlop = PAGING_TOUCH_SLOP;
        mDoubleTapSlop = DOUBLE_TAP_SLOP;
        mWindowTouchSlop = WINDOW_TOUCH_SLOP;
        //noinspection deprecation
        mMaximumDrawingCacheSize = MAXIMUM_DRAWING_CACHE_SIZE;
        mOverscrollDistance = OVERSCROLL_DISTANCE;
        mOverflingDistance = OVERFLING_DISTANCE;
        mFadingMarqueeEnabled = true;
    }

/**
     * @return Distance in pixels a touch can wander before we think the user is scrolling
     */
    public int getScaledTouchSlop() {
        return mTouchSlop;
    }

}


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
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值