Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
364 views
in Technique[技术] by (71.8m points)

android - When using the CoordinatorLayout my ScrollView has an incorrect size

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...