簡體   English   中英

設備解鎖后無法滾動 - CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout

[英]Cannot scroll after device unlock - CoordinatorLayout, AppBarLayout, CollapsingToolbarLayout

我有一個帶有可折疊標題的頁面。 鎖定和解鎖設備后,我無法滾動標題(有時在我轉到另一個片段並再次返回時會發生這種情況)。 我只能通過觸摸正文(而不是標題)來滾動。

感謝您的回答。

這是我的代碼:

<android.support.design.widget.CoordinatorLayout
    android:id="@+id/coordinator"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/app_bar_layout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@null">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/toolbar_layout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:layout_scrollFlags="scroll|enterAlwaysCollapsed">

            <include
                android:id="@+id/event_detail_header"
                layout="@layout/view_event_detail_header"
                app:item="@{item}" />

        </android.support.design.widget.CollapsingToolbarLayout>

        <android.support.design.widget.TabLayout
            android:id="@+id/tab_layout"
            style="@style/AppTabLayout"
            android:layout_width="match_parent" />

    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/pager"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior" />

</android.support.design.widget.CoordinatorLayout>

通過模擬點擊修復。

    View nestedScrollView = view.findViewById(R.id.nested_scroll_view);
    if (nestedScrollView != null) {
        float posX = 0.0f;
        float posY = 0.0f;
        int state = 0;

        // Prepare and perform fake action down
        long downTime = SystemClock.uptimeMillis();
        long eventTime = SystemClock.uptimeMillis() + 100;
        int eventType = MotionEvent.ACTION_DOWN;
        MotionEvent motionEvent = MotionEvent.obtain(downTime, eventTime, eventType, posX, posY, state);
        nestedScrollView.dispatchTouchEvent(motionEvent);

        // Prepare and perform fake action up
        downTime = SystemClock.uptimeMillis();
        eventTime = SystemClock.uptimeMillis() + 100;
        eventType = MotionEvent.ACTION_DOWN;
        motionEvent = MotionEvent.obtain(downTime, eventTime, eventType, posX, posY, state);
        nestedScrollView.dispatchTouchEvent(motionEvent);
    }

暫無
暫無

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

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