使用 CoordinatorLayout 时,我的 ScrollView 大小不正确 [英] When using the CoordinatorLayout my ScrollView has an incorrect size

本文介绍了使用 CoordinatorLayout 时,我的 ScrollView 大小不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在布局中使用 ScrollView,并尝试使用新的 CoordinatorLayout 来自设计支持库.

I'm using a ScrollView in a layout, and am attempting to use the new CoordinatorLayout from the design support library.

我的布局文件如下所示:

My layout file looks like this:

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

  <ScrollView
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      app:layout_behavior="@string/appbar_scrolling_view_behavior">
    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical">
      ...
    </LinearLayout>
  </ScrollView>
  <android.support.design.widget.AppBarLayout
      android:layout_width="match_parent"
      android:layout_height="wrap_content">
    <android.support.v7.widget.Toolbar ... />
  </android.support.design.widget.AppBarLayout>
</android.support.design.widget.CoordinatorLayout>

测试时,滚动视图仅占据屏幕的一部分.出了什么问题?

When testing this the scrollview only occupies part of the screen. What went wrong?

推荐答案

标准的 ScrollView 只能用作父级.您需要将 ScrollView 更改为 android.support.v4.widget.NestedScrollView.

The standard ScrollView is only meant to be used as a parent. You need to change the ScrollView to a android.support.v4.widget.NestedScrollView.

一个例子可以在AppBarLayout.

An example can be seen in the reference documentation for AppBarLayout.

这篇关于使用 CoordinatorLayout 时,我的 ScrollView 大小不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆