java - 设备解锁后无法滚动 - CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout

标签 java android

我有一个带有可折叠标题的页面。锁定和解锁设备后,我无法滚动标题(有时当我转到另一个 fragment 并再次返回时会发生这种情况)。我只能通过触摸正文(而不是标题)来滚动。

感谢您的回答。

这是我的代码:

<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);
    }

关于java - 设备解锁后无法滚动 - CoordinatorLayout、AppBarLayout、CollapsingToolbarLayout,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53226938/

相关文章:

java - 似乎无法在 android 中解析 xml 文件而不出现 saxparser 意外 token 错误

android - 在 onClick 处理程序的 Activity 类 android.view.ContextThemeWrapper 中找不到方法 onClick(View)

android - 关于 NotifyDataSetChanged

java - Spring Webflux Mono : unable to collect the results as List

java - 是否可以在不使用编译器标志的情况下在同一个项目中混合使用 Java 8 和 Java 9 源代码?

使用消息队列的 Java C 集成

java - 线程ID=1 : thread exiting with uncaught exception (group=0x41cd1700)

java - 如何在所有子线程执行完毕后运行主线程

java - 如何用SVNkit识别SVN路径是目录还是文件?

android - 用动态文件填充MediaPlayer