web-dev-qa-db-fra.com

SwipeRefreshLayout avec NestedScrollView et LinearLayout

<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>

Je voudrais que la disposition linéaire avec les données soit en dessous du "textViewAppBar". J'ai essayé d'implémenter un RelativeLayout mais cela ne fonctionne pas. Maintenant, les données s'affichent dans la mise en page complète, mais j'aimerais avoir ceci sous le "textViewAppBar" mais le SwipeRefreshLayout doit être match_parent, des suggestions? Merci :-)

24
FabASP

app:layout_behavior doit être ajouté à l'enfant direct de CoordinatorLayout.

Vous devez donc déplacer app:layout_behavior="@string/appbar_scrolling_view_behavior" de NestedScrollView à 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>
37
leveme

utilisez ceci

<Android.support.v4.widget.SwipeRefreshLayout 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:id="@+id/swipeContainer"
Android:layout_width="match_parent"
Android:layout_height="match_parent">

<Android.support.design.widget.CoordinatorLayout
    ... your attribute here ... >

    <Android.support.design.widget.AppBarLayout
        ... your attribute here ... >

        <Android.support.design.widget.CollapsingToolbarLayout
            ... your attribute here ... >

            ... your element here ...

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

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

    <Android.support.v4.widget.NestedScrollView
        ... your attribute here ... >

        ... your element here ...

    </Android.support.v4.widget.NestedScrollView>
</Android.support.design.widget.CoordinatorLayout>
6
raditya gumay

Je l'ai résolu par moi-même pour mettre SwipeRefreshLayout en tant que disposition principale et ajouter le reste en tant qu'enfants

4
FabASP

app: layout_behavior doit être ajouté à l'enfant direct de CoordinatorLayout. et après avoir besoin d'utiliser NestedScrollView dans SwipeLayout comme;

<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>
4
Ozan Urkan

Vous devez ajouter votre code:

        recyclerView.setNestedScrollingEnabled(false)
0
Tony