Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

改变density导致滑动手势的判定出现问题,已附上解决方案。 #443

Open
5 tasks done
ErgooLee opened this issue Jun 5, 2023 · 0 comments
Open
5 tasks done

Comments

@ErgooLee
Copy link

ErgooLee commented Jun 5, 2023

Environment

  • Autosize Version: V1.2.1
  • Target Android Version: 32
  • Device Model: xiaomi
  • Device Resolution: 2880*1800
  • Design Size On AndroidManifest: 2880dp * 1800dp

Bug Description:

ViewConfiguration类中定义了几个滑动和点击之间的判定参数,如mTouchSlop,默认是8dp,档density=2.0时,mTouchSlop=16px,当滑动距离超过这个值时,会判定为滑动,反之则判定为点击。但是AutoSize改变了density,导致mTouchSlop的值同样发生放大或者缩小,进而导致滑动误触或者很难触发滑动。比如我用GestureDetector去判定长按。原本density=2.0,mTouchSlop=16,用auto size后
mTouchSlop=7,导致长按很难触发,会被判定为滑动。

Log:

不需要

Related Code:

可以查看GestureDetector里长按手势的判定逻辑

//判定阈值
  touchSlop = configuration.getScaledTouchSlop();


public static ViewConfiguration get(@NonNull @UiContext Context context) {
        StrictMode.assertConfigurationContext(context, "ViewConfiguration");

        final DisplayMetrics metrics = context.getResources().getDisplayMetrics();
        final int density = (int) (100.0f * metrics.density);

        ViewConfiguration configuration = sConfigurations.get(density);
        if (configuration == null) {
            configuration = new ViewConfiguration(context);
            sConfigurations.put(density, configuration);
        }

        return configuration;
    }

解决方案:

AutoSize应该只改变ui相关的density,非ui相关的density应该还原。
可以通过反射将ViewConfiguration还原。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant