android - scrollView 可以滚动多少?

标签 android android-layout layout scroll onmeasure

我有一个布局,里面有一个 scrollView。

如何计算可能的滚动尺寸?

我认为:

(scroll's content desired height) - window.height = (invisible content height)

但是如何让滚动条的内容达到实际需要的高度呢?

我可以得到scrollView的高度,这不是我需要的。

我看到了这个post ,但我没有得到计算结果。

int diff = (view.getBottom() - (getHeight() + getScrollY()));//计算

最佳答案

// you can do it by the following two attributes in xml in scrollview it will scroll 
//accroding to the child views it contain
     android:animateLayoutChanges="true"
     android:orientation="vertical"

//here is the full example 
 <ScrollView
 xmlns:android="http://schemas.android.com/apk/res/android"
 xmlns:tools="http://schemas.android.com/tools"
 android:layout_width="match_parent"
 android:layout_height="wrap_content"
 android:layout_marginBottom="50dp"
 android:animateLayoutChanges="true"
 android:orientation="vertical"
 tools:context=".fragments.frag1"
 >
  <RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@drawable/bgsecond"
    android:layout_marginBottom="40dp"
     >
  </RelativeLayout>
 </ScrollView>

关于android - scrollView 可以滚动多少?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55908152/

相关文章:

android - 仅在 API 19 上围绕 FloatingActionButton 的额外边距(间距)

android - 使用私有(private)样式(找不到与给定名称匹配的资源)

Java3D 与 Canvas3D 和按钮重叠

css - 元素位置,取决于其尺寸

android - 将android中XYplot的背景颜色更改为白色?

javascript - Android 脚本层 - LibGDX

android - 无法在文本更改时调整项目组并尊重边距

java - 膨胀类 com.google.ads.AdView 时出错

android - 更新后应用强制不断关闭

Android强制水平(横向)布局