android - 无法在 NestedScrollView 中完全滚动

标签 android android-layout layout

不知何故,我无法在我的 NestedScrollView 中完全滚动。在我的 NestedScrollView 中有一个 TextView,它下面有很多文本和一个按钮。当我向下滚动时,我只能看到按钮的顶部(只有几个像素)。它滚动得不够远。

这是我的布局:

<?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"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

<android.support.design.widget.AppBarLayout
        android:id="@+id/appbar"
        android:layout_width="match_parent"
        android:stateListAnimator="@drawable/appbar_always_elevated"
        android:layout_height="128dp">

    <android.support.design.widget.CollapsingToolbarLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            app:contentScrim="?attr/colorPrimary"
            app:layout_scrollFlags="scroll|enterAlways|exitUntilCollapsed"
            app:toolbarId="@+id/toolbar">

        <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                app:title="@string/app_name"
                app:layout_collapseMode="pin">

        </android.support.v7.widget.Toolbar>
    </android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>


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

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="match_parent"
            android:layout_height="match_parent">

        <TextView
                android:id="@+id/textView"
                style="@style/Text.Body1.Medium"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_marginStart="@dimen/margin"
                android:layout_marginTop="@dimen/margin"
                android:layout_marginEnd="@dimen/margin"
                android:text="@string/large_text"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"
                app:layout_constraintTop_toBottomOf="@id/appbar"/>

        <Button
                android:id="@+id/continueButton"
                style="@style/Widget.Button.Green"
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="@dimen/margin"
                android:layout_marginStart="@dimen/margin"
                android:layout_marginEnd="@dimen/margin"
                android:layout_marginBottom="@dimen/margin"
                android:text="@string/continue_text"
                app:layout_constraintBottom_toBottomOf="parent"
                app:layout_constraintEnd_toEndOf="parent"
                app:layout_constraintStart_toStartOf="parent"/>
    </LinearLayout>
   </android.support.v4.widget.NestedScrollView>

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

最佳答案

NestedScrollView 中的 LinearLayout 的高度更改为 wrap_content

NestedScrollView 及其单个滚动 subview 背后的想法是外部( ScrollView )应该有一些固定/预定的高度,内部(滚动的 child )应该有一个比 parent 大的动态高度。毕竟,如果内容不大于父级,那么滚动是什么?

关于android - 无法在 NestedScrollView 中完全滚动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53598676/

相关文章:

使用微调器从国家名称中获取 Android 国家/地区代码

java - 在自定义 Alert Builder View 布局中未从 EditText 获取文本

android - 不管 View 层次结构如何,调用 TextView.setText() 都会重绘整个屏幕

css - 展开网格 100% 其父 div,没有其他卷轴

java - Android:需要格式化布局的帮助

xml - 在 Android 中构建/使用运行时生成的布局 XML

Android 应用程序在签名后无法对 HTTPS 进行 ajax 调用

android - 在运行时询问 WebView 的摄像头权限

android - 如何在一些时间间隔后一个一个地动画多个对象android

java - 在android中的tabhost中添加滚动