簡體   English   中英

使用ViewTreeObserver向右滾動水平ScrollView完整滾動焦點

[英]Horizontal ScrollView full Scroll focus right with ViewTreeObserver

我正在動態地將對象添加到水平滾動視圖中,當我添加下面的代碼可以很好地向右移動時,現在的問題是當我嘗試通過交換手指滾動回到左側時,下面的代碼再次運行並且水平滾動視圖滾動到了再次在右上角,這有點令人討厭,任何人都有一些替代解決方案,我已經嘗試過

Postdelayed()

但這對我來說無法正常工作

ViewTreeObserver viewTreeObserver = hScrollView.getViewTreeObserver();
        if (viewTreeObserver.isAlive()) {
            viewTreeObserver
                    .addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
                        @Override
                        public void onGlobalLayout() {
                            // interestedInView is ready for size and position
                            // queries because it has been laid out
                            hScrollView
                                    .fullScroll(HorizontalScrollView.FOCUS_RIGHT);
                        }
                    });
        }

關於MGD

創建滾動視圖時,版圖編輯器是否在那里將視圖一直滾動到最右邊? 如果是這樣,則應在onGlobalLayout函數中刪除事件偵聽器,否則在布局時它將向右滾動。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM