我收到此錯誤:調用API需要14級(當前分鐘8):android.view.ViewGroup#canScrollHorizontally
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;
}
}
}
使用支持庫:http://developer.android.com/reference/android/support/v4 /view/ViewCompat.html#canScrollHorizontal(android.view.View,int) – 2014-10-03 08:43:51
它取決於你,如果你想支持更多最新的Android手機,你可以增加你的API級別爲14 ...否則你必須找到另一種替代方案你想要做什麼,這只是一個建議 – danidee 2014-10-03 08:44:41
你不清楚你是否寫了一個名爲canScrollHorizotnally的方法,或者你想使用框架提供的那個 – Blackbelt 2014-10-03 08:45:01