gpt4 book ai didi

android - 调用需要 API 级别 14(当前最小值为 8): android. view.ViewGroup#canScrollHorizo​​ntally

转载 作者:行者123 更新时间:2023-11-29 21:00:44 25 4
gpt4 key购买 nike

我收到这个错误:

Call requires API level 14 (current min is 8): android.view.ViewGroup#canScrollHorizontally.

我如何在 14 之前的 API 级别解决这个问题?

public class ViewPagerEx extends ViewGroup{
@Override
public boolean performAccessibilityAction(View host, int action, Bundle args) {
if (super.performAccessibilityAction(host, action, args)) {
return true;
}
switch (action) {
case AccessibilityNodeInfoCompat.ACTION_SCROLL_FORWARD: {
if (canScrollHorizontally(1)) {
setCurrentItem(mCurItem + 1);
return true;
}
} return false;
case AccessibilityNodeInfoCompat.ACTION_SCROLL_BACKWARD: {
if (canScrollHorizontally(-1)) {
setCurrentItem(mCurItem - 1);
return true;
}
} return false;
}
return false;
}

public boolean canScrollHorizontally(int direction) {
if (mAdapter == null) {
return false;
}
final int width = getClientWidth();
final int scrollX = getScrollX();
if (direction < 0) {
return (scrollX > (int) (width * mFirstOffset));
} else if (direction > 0) {
return (scrollX < (int) (width * mLastOffset));
} else {
return false;
}
}
}

最佳答案

来自@KenWolf 的建议:使用 support-v4库,您可以使用 ViewCompat 来检查:

// From within the View itself, just invoke the ViewCompat
// implementation with 'this' as the View parameter.
if (ViewCompat.canScrollHorizontally(this, 1)) {
// ...
}

关于android - 调用需要 API 级别 14(当前最小值为 8): android. view.ViewGroup#canScrollHorizo​​ntally,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26175839/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com