【问题标题】:Why does scroll view continue to scroll in nothingness?为什么滚动视图在虚无中继续滚动?
【发布时间】:2017-08-02 06:35:54
【问题描述】:

在我的应用程序中,scrollView 中有一个 ConstraintLayout,但我遇到了 ConstrainLayout 高度的问题,我的意思是如果我将高度设置为 0 或 wrap_content 或类似 420dp 的东西保持不变并且因此,如果没有内容,滚动视图也会继续滚动 ConstraintLayout

这是一个相关的截图:

更新完整的 XML 代码

XML CODE HERE我不得不上传到github,因为它有点长...

【问题讨论】:

  • 如果 ScrollView 是 ConstraintLayout 的父级,为什么要将 ConstraintLayout 布局参数设置为 ScrollView?
  • @lelloman 的截图看起来更好,这不是唯一的 ConstraintLayout。
  • 你正在为你的滚动视图设置垂直约束,为什么给它520dp的固定高度?将其设置为 0dp 以匹配其父项
  • 请把问题中的代码贴出来,不需要使用外部链接
  • @lelloman 将其设置为 520dp 我正在通过隐藏滚动视图中的淡入淡出效果来做一个技巧,这只是图形的原因。

标签: java android android-layout android-scrollview


【解决方案1】:

由于这个原因,您的滚动视图滚动,因此您正在为滚动视图提供静态高度

使您的滚动视图高度 android:layout_height="520dp"android:layout_height="wrap_content" android:layout_height="match_parent" 像这样

<ScrollView
android:id="@+id/scrollView2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:fillViewport="true"
android:layout_marginBottom="8dp"
android:layout_marginEnd="8dp"
android:layout_marginLeft="8dp"
android:layout_marginRight="8dp"
android:layout_marginStart="8dp"
android:layout_marginTop="80dp"
>

【讨论】:

  • 什么都没有改变,因为 scrollView 将包裹 ConstraintView 所以它仍然保持不变...
  • 其实真正的问题不是scrollView,而是ConstrainView,请看截图更好。
  • @I.Mytyuk 提供你的整个 xml 布局文件
【解决方案2】:

将您的滚动视图高度宽度设置为 match_parent 并将 fillViewPort 设置为 true。

<ScrollView
   android:id="@+id/scrollView2"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:fillViewport="true"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2023-03-30
    • 2013-11-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多