NestedScrollView剂量滚动到Fragment的末尾

时间:2018-07-03 08:49:30

标签: android xml android-layout android-fragments nestedscrollview

我有一个Activity使用FragmentsViewPager打开多个TabLayout。当我尝试使用NestedScrollView实现片段的滚动时,我无法一直滚动到片段的末尾。此布局是否缺少或不正确?

demo

活动布局:

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:fresco="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/detail_app_bar"
        android:layout_width="match_parent"
        android:layout_height="240dp"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
        app:layout_scrollFlags="scroll|exitUntilCollapsed">

        <android.support.design.widget.CollapsingToolbarLayout
            android:id="@+id/detail_collapsing_toolbar"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="@color/colorPrimary"
            app:expandedTitleMargin="@dimen/horizontal_margin"
            app:layout_scrollFlags="scroll|exitUntilCollapsed|snap">

            <com.facebook.drawee.view.SimpleDraweeView
                android:id="@+id/detail_photo"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:fitsSystemWindows="true"
                android:scaleType="centerCrop"
                app:actualImageScaleType="focusCrop"
                app:layout_collapseMode="parallax"
                app:placeholderImageScaleType="centerInside"
                app:viewAspectRatio="1.33"
                fresco:placeholderImage="@drawable/empty_detail" />

            <android.support.v7.widget.Toolbar
                android:id="@+id/detail_toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:contentInsetStart="@dimen/horizontal_margin"
                app:layout_collapseMode="pin"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />


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


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



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

            <android.support.design.widget.TabLayout
                android:id="@+id/detail_tab_layout"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:tabGravity="fill"
                app:tabMode="fixed"
                app:tabSelectedTextColor="@color/colorAccent"
                app:tabTextColor="@color/tertiaryText" />

        </android.support.v4.view.ViewPager>


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

片段布局:

<android.support.v4.widget.NestedScrollView 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"
    android:fillViewport="true"
    android:background="@color/White"
    android:clipToPadding="false"

    android:padding="16dp"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".UI.Details.DetailsActivity">


    <android.support.constraint.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <android.support.constraint.Guideline
            android:id="@+id/guideline"
            android:layout_width="8dp"
            android:layout_height="match_parent"
            android:orientation="vertical"
            app:layout_constraintGuide_percent="0.5" />

        <TextView
            android:id="@+id/current_temp"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:text="TextView"
            android:textSize="45sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toTopOf="parent" />

        <ImageView
            android:id="@+id/weather_condition_image"
            android:layout_width="140dp"
            android:layout_height="144dp"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="8dp"
            android:src="@drawable/ic_thunderstrom"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.498"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/current_temp" />

        <TextView
            android:id="@+id/weather_condition_text"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginEnd="8dp"
            android:layout_marginLeft="8dp"
            android:layout_marginRight="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="24dp"
            android:text="TextView"
            android:textSize="20sp"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/weather_condition_image" />

        <LinearLayout
            android:id="@+id/linearLayout1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="48dp"
            android:layout_marginStart="48dp"
            android:layout_marginTop="16dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toTopOf="@+id/linearLayout3"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/weather_condition_text">

            <TextView
                android:id="@+id/sunrise"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/sunrise" />

            <TextView
                android:id="@+id/sunrise_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="5:00am"
                android:textColor="@color/Black"
                android:textSize="20sp" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/linearLayout2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toTopOf="@+id/linearLayout4"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.300"
            app:layout_constraintStart_toStartOf="@+id/guideline"
            app:layout_constraintTop_toBottomOf="@+id/weather_condition_text">

            <TextView
                android:id="@+id/sunset"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/sunset" />

            <TextView
                android:id="@+id/sunset_time"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="6:00pm"
                android:textColor="@color/Black"
                android:textSize="20sp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="48dp"
            android:layout_marginStart="48dp"
            android:layout_marginTop="16dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toTopOf="@+id/linearLayout5"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout1">

            <TextView
                android:id="@+id/humidity"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/humidity" />

            <TextView
                android:id="@+id/humidity_percent"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="83%"
                android:textColor="@color/Black"
                android:textSize="20sp" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/linearLayout4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="8dp"
            android:layout_marginStart="8dp"
            android:layout_marginTop="16dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toTopOf="@+id/linearLayout6"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.300"
            app:layout_constraintStart_toStartOf="@+id/guideline"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout2">

            <TextView
                android:id="@+id/wind"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/wind" />

            <TextView
                android:id="@+id/wind_speed"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="5.1mph"
                android:textColor="@color/Black"
                android:textSize="20sp" />
        </LinearLayout>

        <LinearLayout
            android:id="@+id/linearLayout5"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginLeft="48dp"
            android:layout_marginStart="48dp"
            android:layout_marginTop="16dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintHorizontal_bias="0.5"
            app:layout_constraintStart_toStartOf="parent"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout3">

            <TextView
                android:id="@+id/min_temp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/temp_min" />

            <TextView
                android:id="@+id/min_temp_value"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="72"
                android:textColor="@color/Black"
                android:textSize="20sp" />
        </LinearLayout>


        <LinearLayout
            android:id="@+id/linearLayout6"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="16dp"
            android:orientation="vertical"
            app:layout_constraintBottom_toBottomOf="parent"
            app:layout_constraintEnd_toEndOf="parent"
            app:layout_constraintHorizontal_bias="0.340"
            app:layout_constraintStart_toStartOf="@+id/guideline"
            app:layout_constraintTop_toBottomOf="@+id/linearLayout4">

            <TextView
                android:id="@+id/max_temp"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/temp_max" />

            <TextView
                android:id="@+id/max_temp_value"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="80"
                android:textColor="@color/Black"
                android:textSize="20sp" />
        </LinearLayout>


    </android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>

0 个答案:

没有答案