【发布时间】:2016-09-17 21:43:37
【问题描述】:
最近,Android Studio 2.2 有了一个新的 ConstraintLayout,它使设计变得更加容易,但与 RelativeLayout 和 Linearlayout 不同,我不能使用 ScrollView 来包围 ConstraintLayout。这可能吗?如果有,怎么做?
即
<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>
【问题讨论】:
-
是什么阻止你这样做?您总是可以直接在 XML 中添加一个...
-
您应该添加代码以及遇到的任何错误。
-
如果我使用
layout_height="wrap_content",应用程序会显示一个空白屏幕,但如果我使用layout_height="match_parent",应用程序将不会滚动。 -
显然当将 layout_height 设置为“wrap_content”时,ConstraintLayout 会以某种方式忽略它的子元素并崩溃。即使子元素已经定义了有关 ConstraintLayout 的顶部和底部的约束(例如边距),情况也是如此。
-
有什么办法可以让约束布局滚动,还是我应该回去使用不同的布局?
标签: android android-layout user-interface android-constraintlayout