所以最近,使用 Android Studio 2.2 有一个新的 ConstraintLayout 可以让设计变得更容易,但与 RelativeLayout
和 Linearlayout
不同,我不能使用 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 许可协议
ScrollViews 中的 ConstraintLayout 存在错误,已修复。 google 已修复 Android Studio 2.2 Preview 2 (constraintlayout 1.0.0-alpha2) 中的错误。
检查此链接以获取新更新(预览版 2): 在 ScrollView 和 RecycleView 中正常工作
解决方案1:
解决方案2:
编辑 - 20 年 9 月 16 日:
目前,更常见的是使用 ConstraintLayout 高度设置为 wrap_content 的 ScrollView,它工作得很好,不要忘记 fillViewPort 并且 Scroll 和 Nested 都只支持一个直接子级。