【问题标题】:NestedScrollView, LinearLayout overscrolling beyond constraintsNestedScrollView、LinearLayout 超出约束过度滚动
【发布时间】:2020-06-25 02:57:22
【问题描述】:

我试图让三个片段出现在我的可折叠工具栏下方。我有一个线性布局的片段,在一个嵌套的滚动视图中。

片段看起来很好,滚动工作(ish)和线性布局按预期工作。然而,嵌套滚动滚动到它需要去的地方,进入空白空间。所有这些都显示在可折叠工具栏的顶部。

关于如何解决这个问题的任何想法?

我曾尝试在 NestScroll 上使用 app:layout_behavior="@string/appbar_scrolling_view_behavior">,但它只是将一半列表隐藏在可折叠工具栏后面,并且仍然过度滚动。

    <androidx.core.widget.NestedScrollView
        android:id="@+id/nestedScroll"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:fitsSystemWindows="false"
        android:overScrollMode="never"
        app:layout_anchor="@+id/appBarLayout"
        app:layout_anchorGravity="bottom">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_gravity="bottom"
            android:orientation="vertical"
            android:padding="16dp"
            android:paddingBottom="20dp"
            app:layout_anchor="@+id/nestedScroll"
            app:layout_anchorGravity="bottom">

            <fragment
                android:id="@+id/overdueFrag"
                android:name="com.grove.groveone.FragmentHomeList"
                android:layout_width="match_parent"
                android:layout_height="match_parent" />

            <fragment
                android:id="@+id/dueSoonFrag"
                android:name="com.grove.groveone.FragmentHomeList"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />


            <fragment
                android:id="@+id/paidFrag"
                android:name="com.grove.groveone.FragmentHomeList"
                android:layout_width="match_parent"
                android:layout_height="wrap_content" />

        </LinearLayout>

    </androidx.core.widget.NestedScrollView>



编辑:

根据要求,工具栏 xml。

<androidx.coordinatorlayout.widget.CoordinatorLayout 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/coordinator_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <com.google.android.material.appbar.AppBarLayout
        android:id="@+id/appBarLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/groveMainPurple">

        <com.google.android.material.appbar.CollapsingToolbarLayout

            android:id="@+id/toolbarCollapsingLayout"
            android:layout_width="match_parent"
            android:layout_height="245dp"
            app:contentScrim="@color/groveMainPurple"
            app:layout_scrollFlags="snap|scroll|exitUntilCollapsed">


            <androidx.constraintlayout.widget.ConstraintLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent">

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/textRentPaymentTitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginBottom="5dp"
                    android:text="@string/rent_payments"
                    android:textColor="@color/whiteGroveText"
                    android:textSize="22dp"
                    app:layout_constraintBottom_toTopOf="@+id/textRentalIncomeSubtitle"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toTopOf="parent" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/textRentMonthlySum"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="7dp"
                    android:layout_marginBottom="7dp"
                    android:fontFamily="@font/roboto_medium"
                    android:text="$"
                    android:textColor="@color/whiteGroveText"
                    android:textSize="45dp"
                    app:layout_constraintBottom_toTopOf="@+id/textRentalIncomeSubtitle"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@+id/textRentPaymentTitle" />

                <androidx.appcompat.widget.AppCompatTextView
                    android:id="@+id/textRentalIncomeSubtitle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginStart="15dp"
                    android:layout_marginTop="5dp"
                    android:text="@string/rental_income_this_month"
                    android:textColor="@color/whiteGroveText"
                    app:layout_constraintStart_toStartOf="parent"
                    app:layout_constraintTop_toBottomOf="@id/textRentMonthlySum" />

            </androidx.constraintlayout.widget.ConstraintLayout>

            <androidx.appcompat.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:theme="@style/ThemeOverlay.AppCompat.Dark" />

        </com.google.android.material.appbar.CollapsingToolbarLayout>

    </com.google.android.material.appbar.AppBarLayout>

【问题讨论】:

  • 请附上app bar的xml
  • @Nidheesh 已添加。干杯!

标签: android xml android-fragments android-linearlayout android-scrollview


【解决方案1】:

同样的事情发生在我身上。我将资源文件中RecyclerView 的布局宽度/高度更改为width:match_parent height:wrap_content。当我检查它们时,这些值被设置为静态值。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2016-04-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-10-27
    相关资源
    最近更新 更多