ollView和LinearLayout的SwipeRefres

ollView和LinearLayout的SwipeRefres

本文介绍了带有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">

                    <!--<TextView-->
                    <!--android:id="@+id/textViewInternet"-->
                    <!--android:layout_width="match_parent"-->
                    <!--android:layout_height="wrap_content"-->
                    <!--android:textColor="@color/black"/>-->


                </LinearLayout>
                <!--</android.support.v4.widget.SwipeRefreshLayout>-->
            </android.support.v4.widget.NestedScrollView>
        </android.support.v4.widget.SwipeRefreshLayout>

        <android.support.design.widget.FloatingActionButton
            android:id="@+id/btnFAB"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom|right"
            android:layout_marginBottom="@dimen/codelab_fab_margin_bottom"
            android:layout_marginRight="@dimen/codelab_fab_margin_right"
            android:src="@drawable/ic_plus_blue"
            app:fabSize="normal">

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

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

我希望数据的线性布局位于"textViewAppBar"下方.我试图实现RelativeLayout,但是它不起作用.现在,数据显示为完整的布局,但是我想在"textViewAppBar"下面显示它,但是SwipeRefreshLayout应该是match_parent,有什么建议吗?谢谢:-)

I would like to have that the linearlayout with the data is below the "textViewAppBar". I have tried to implement a RelativeLayout but it doesn't work. Now, the data is showing to the full layout but I would like to have this below the "textViewAppBar" but the SwipeRefreshLayout shall be match_parent, any suggestions? Thanks :-)

推荐答案

app:layout_behavior 应该添加到 CoordinatorLayout 的直接子级中.

app:layout_behavior should be added to the direct child of CoordinatorLayout.

因此,您应该将 app:layout_behavior ="@ string/appbar_scrolling_view_behavior" NestedScrollView 移到 SwipeRefreshLayout .

So you should move app:layout_behavior="@string/appbar_scrolling_view_behavior" from NestedScrollView to SwipeRefreshLayout.

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

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

    <android.support.v4.widget.SwipeRefreshLayout
        android:id="@+id/swipe_container"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior">

        <android.support.v4.widget.NestedScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:fillViewport="true">
            ...
        </android.support.v4.widget.NestedScrollView>

    </android.support.v4.widget.SwipeRefreshLayout>

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

这篇关于带有NestedScrollView和LinearLayout的SwipeRefreshLayout的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-24 19:53