是否可以将 ConstraintLayout 放在 ScrollView 中?

新手上路,请多包涵

所以最近,使用 Android Studio 2.2 有一个新的 ConstraintLayout 可以让设计变得更容易,但与 RelativeLayoutLinearlayout 不同,我不能使用 ScrollView 环绕 ConstraintLayout 。这可能吗?如果是这样,怎么做?

IE

 <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"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp">

        <android.support.constraint.ConstraintLayout
            android:id="@+id/constraintLayout"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            tools:layout_editor_absoluteX="0dp"
            tools:layout_editor_absoluteY="0dp">

            <!-- Have whatever children you want inside -->

        </android.support.constraint.ConstraintLayout>

</ScrollView>

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

阅读 1.3k
2 个回答

ScrollViews 中的 ConstraintLayout 存在错误,已修复。 google 已修复 Android Studio 2.2 Preview 2 (constraintlayout 1.0.0-alpha2) 中的错误。

检查此链接以获取新更新(预览版 2): 在 ScrollView 和 RecycleView 中正常工作

解决方案1:

解决方案是在 android:fillViewport="true" 上使用 ScrollView

解决方案2:

使用 NestedScrollView 代替 ScrollViewandroid:fillViewport="true"

编辑 - 20 年 9 月 16 日:

目前,更常见的是使用 ConstraintLayout 高度设置为 wrap_content 的 ScrollView,它工作得很好,不要忘记 fillViewPort 并且 Scroll 和 Nested 都只支持一个直接子级。

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

将带有 RelativeLayout 的 ScrollView 放在 ContaintLayout 中。它适用于我的情况。

 <androidx.constraintlayout.widget.ConstraintLayout
    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"
    tools:context=".MainActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent" >

            <!-- your code   -->

        </RelativeLayout>

    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

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

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