日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

安卓开发37:自定义的HorizontalScrollView类,使其pageScroll的时候焦点不选中

發(fā)布時間:2025/5/22 编程问答 31 豆豆
生活随笔 收集整理的這篇文章主要介紹了 安卓开发37:自定义的HorizontalScrollView类,使其pageScroll的时候焦点不选中 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

自定義一個HorizontalScrollView類,主要為了讓這個HorizontalScrollView不能鼠標點擊,不能左右按鍵,并且沒有焦點。


public class ImageMoveHorizontalScrollView extends HorizontalScrollView {private boolean mSmoothScrollingEnabled = true;private final Rect mTempRect = new Rect();public ImageMoveHorizontalScrollView(Context context, AttributeSet attrs) {super(context, attrs);}public ImageMoveHorizontalScrollView(Context context) {super(context);}/*** 關閉鼠標點擊的效果,重寫該方法*/@Overridepublic boolean onTouchEvent(MotionEvent ev) {return false;}/*** 關閉左右按鍵效果,重寫該方法*/@Overridepublic boolean executeKeyEvent(KeyEvent event) {return false;}/*** 去除焦點選中*/@Overridepublic boolean pageScroll(int direction) {boolean right = direction == View.FOCUS_RIGHT;int width = getWidth();if (right) {mTempRect.left = getScrollX() + width;int count = getChildCount();if (count > 0) {View view = getChildAt(0);if (mTempRect.left + width > view.getRight()) {mTempRect.left = view.getRight() - width;}}} else {mTempRect.left = getScrollX() - width;if (mTempRect.left < 0) {mTempRect.left = 0;}}mTempRect.right = mTempRect.left + width;return scrollAndFocus(direction, mTempRect.left, mTempRect.right);}private boolean scrollAndFocus(int direction, int left, int right) {boolean handled = true;int width = getWidth();int containerLeft = getScrollX();int containerRight = containerLeft + width;boolean goLeft = direction == View.FOCUS_LEFT; //主要在這邊,注釋掉下面的代碼// View newFocused = findFocusableViewInBounds(goLeft, left, right);// if (newFocused == null) {// newFocused = this;// }if (left >= containerLeft && right <= containerRight) {handled = false;} else {int delta = goLeft ? (left - containerLeft) : (right - containerRight);doScrollX(delta);}//去除 滾動后 foucus的// if (newFocused != findFocus())// newFocused.requestFocus(direction);return handled;}/*** Smooth scroll by a X delta* @param delta the number of pixels to scroll by on the X axis*/private void doScrollX(int delta) {if (delta != 0) {if (mSmoothScrollingEnabled) {smoothScrollBy(delta, 0);} else {scrollBy(delta, 0);}}}}


使用:

?

sc.pageScroll(View.FOCUS_RIGHT); //向右翻一頁


?

?

總結

以上是生活随笔為你收集整理的安卓开发37:自定义的HorizontalScrollView类,使其pageScroll的时候焦点不选中的全部內容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。