是否可以将 ConstraintLayout 放在 ScrollView 中? [英] Is it possible to put a ConstraintLayout inside a ScrollView?
问题描述
最近,在 Android Studio 2.2 中,有一个新的 ConstraintLayout 使设计更容易,但与 RelativeLayout
和 Linearlayout
不同,我不能使用 ScrollView
包围 ConstraintLayout
.这可能吗?如果是,怎么办?
So recently, with Android Studio 2.2 there's a new ConstraintLayout that makes designing a lot easier, but unlike RelativeLayout
and Linearlayout
, I can't use a ScrollView
to surround ConstraintLayout
. Is this possible? If so, how?
即
<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>
推荐答案
ScrollViews 中的 ConstraintLayout 存在一个错误,现已修复.google 已修复 Android Studio 2.2 Preview 2 (constraintlayout 1.0.0-alpha2) 中的错误.
There was a bug with ConstraintLayout inside ScrollViews and it has been fixed. google has fixed the bug in Android Studio 2.2 Preview 2 (constraintlayout 1.0.0-alpha2).
检查此链接以获取新更新(预览 2):在 ScrollView 和 RecycleView 中正常工作
Check this link for new update (Preview 2): works properly inside ScrollView and RecycleView
解决方案 1:
解决方案是使用 android:fillViewport="true"
在ScrollView
解决方案 2:
使用 NestedScrollView
代替 ScrollView
和 android:fillViewport=true"
编辑 - 09/16/20:
目前更常用的是将 ScrollView 的 ConstraintLayout 高度设置为 wrap_content,效果很好,别忘了 fillViewPort,而且 Scroll 和 Nested 都只支持一个直接子级.
Currently, it is more usual to use the ScrollView with the ConstraintLayout height set to wrap_content, it works very well, don't forget the fillViewPort and that both Scroll and Nested support only one direct child.
这篇关于是否可以将 ConstraintLayout 放在 ScrollView 中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!