Android - 如何制作可滚动的约束布局?

新手上路,请多包涵

我想制作一个布局,让我使用约束布局向下滚动,但我不知道该怎么做。 --- 应该是 ScrollView 的父 ConstraintLayout 吗?

 <?xml version="1.0" encoding="utf-8"?>

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

<android.support.constraint.ConstraintLayout
    android:id="@+id/Constraint"
    android:layout_width="match_parent"
    android:layout_height="match_parent"/>

还是反过来?也许有人可以为我指出一个很好的教程或举个例子,我似乎找不到。

另外,我不知道这是一个错误还是我没有设置的一些配置,但我见过这样的图像:

在此处输入图像描述

在蓝图“蓝色矩形”之外有一些组件但它们是可见的,而在我这边,如果我将组件放在“空白”上,我看不到它或将它移动到任何地方,它出现在组件树上.

更新 :

我在设计工具中找到了一种使约束布局可滚动的方法,使用水平引导线将约束布局边框下推并将其延伸到设备之外,之后,您可以使用引导线作为约束布局的新底部来锚定组件。

原文由 gtovar 发布,翻译遵循 CC BY-SA 4.0 许可协议

阅读 699
1 个回答

这里有很多答案,没有什么很简单的。 It’s important that the ScrollView’s layout_height is set to match_parent while the layout_height of the ContraintLayout is wrap_content

 <ScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    >

    <androidx.constraintlayout.widget.ConstraintLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

    ...

原文由 Quintin Balsdon 发布,翻译遵循 CC BY-SA 4.0 许可协议

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题