小编Fab*_*ASP的帖子

使用NestedScrollView和LinearLayout的SwipeRefreshLayout

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

    <!--<include-->
    <!--android:id="@+id/app_bar"-->
    <!--layout="@layout/app_bar" />-->


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

        <android.support.design.widget.AppBarLayout
            android:layout_width="match_parent"
            android:layout_height="256dp">

            <android.support.design.widget.CollapsingToolbarLayout
                android:id="@+id/collapsingToolbarLayout"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                app:contentScrim="?attr/colorPrimary"
                app:expandedTitleMarginStart="64dp"
                app:layout_scrollFlags="scroll|exitUntilCollapsed">

                <ImageView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:scaleType="centerCrop"
                    android:src="@drawable/header"
                    app:layout_collapseMode="parallax"
                    app:layout_collapseParallaxMultiplier="0.7" />

                <android.support.v7.widget.Toolbar
                    android:id="@+id/toolbarTutorial"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:minHeight="?attr/actionBarSize"
                    app:layout_collapseMode="pin"
                    app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                    app:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar" />

                <TextView
                    android:id="@+id/textViewAppBar"
                    android:layout_width="match_parent"
                    android:layout_height="50dp"
                    android:layout_gravity="bottom"
                    android:gravity="center"
                    android:scrollbarDefaultDelayBeforeFade="@id/toolbarTutorial"
                    android:text="test"
                    android:textColor="@color/white"
                    android:textSize="30sp" />


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

            <!--<android.support.design.widget.TabLayout-->
            <!--android:id="@+id/tabLayout"-->
            <!--android:layout_width="match_parent"-->
            <!--android:layout_height="wrap_content"-->
            <!--app:layout_scrollFlags="scroll|enterAlways"/>-->

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


        <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/swipe_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

            <android.support.v4.widget.NestedScrollView
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fillViewport="true"
                app:layout_behavior="@string/appbar_scrolling_view_behavior">


                <!--<android.support.v4.widget.SwipeRefreshLayout-->
                <!--android:id="@+id/activity_main_swipe_refresh_layout"-->
                <!--android:layout_width="match_parent"-->
                <!--android:layout_height="wrap_content">-->
                <LinearLayout
                    android:id="@+id/linearLayoutWithData"
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:orientation="vertical"
                    app:layout_behavior="@string/appbar_scrolling_view_behavior"> …
Run Code Online (Sandbox Code Playgroud)

android swiperefreshlayout

24
推荐指数
4
解决办法
2万
查看次数

Android:检查 NestedScrollView 是在底部还是顶部

我正在使用 NestedScrollView,我想检查 NestedScrollView 是在底部还是顶部 :-)

有什么建议?谢谢!

android nestedscrollview

5
推荐指数
1
解决办法
4087
查看次数

将协程函数作为函数参数传递

我需要传递一个协程函数作为另一个函数的参数。例如:

private fun handleIt(here: Long, call: (hereId: Long) -> Unit) {
            call(here)
}
Run Code Online (Sandbox Code Playgroud)

然后从协程范围:

GlobalScope.launch {
                        handleIt(3) { viewModel.doThings(hereId) }
                    }
Run Code Online (Sandbox Code Playgroud)

viewModel 函数如下所示:

suspend fun doThings(hereId: Long) {
        withContext(coroutineContextProvider.io) {
            doSomething(hereId)
        }
    }
Run Code Online (Sandbox Code Playgroud)

但现在,我收到错误:“只能在协程体内调用暂停函数。有什么建议吗?

coroutine higher-order-functions kotlin

1
推荐指数
1
解决办法
1564
查看次数