Stu*_*ing 16 android android-constraintlayout
我有一个ConstraintLayout内部NestedScrollView.在ConstraintLayout包含了一堆的意见,但最后View能有一个动态的高度,填补了底部空间,当且仅当有什么,但它也需要一个最小高度,如果没有足够的空间.
为了论证,这是一个例子.
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:layout_height="match_parent">
<View
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintHeight_min="1500dp"
android:background="@color/red"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toTopOf="parent"/>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
正如您所看到的,我已将该ConstraintLayout版本放入,但它不起作用.显然,这些值非常大,但这只是用于测试.
如果我不设置fillViewport="true"上NestedScrollView则ConstraintLayout具有0高度时,我设置的fillViewport,在ConstraintLayout不滚动,但只是充满屏幕.
如何设置View以使其扩展到ConstraintLayout应该与Viewport一样大的底部,但如果我的View不是minHeight那么我们允许滚动?
我正在使用1.0.2该ConstraintLayout库的版本.
我期望看到的是一直到父母的底部,但如果那个大小小于1500dp那么视图滚动.
我已经输入1500dp android:layout_height="1500dp",视图会相应滚动.
更新1
似乎是我把布局放在一个FragmentViewPager.该app:layout_constraintHeight_min属性不受尊重,只与视口的高度匹配.
我也尝试NestedScrollView从片段中取出并将其ViewPager放入其中但是再次无效.
Ben*_* P. 24
将此属性添加到您要拉伸的视图中:
app:layout_constraintHeight_default="spread"
Run Code Online (Sandbox Code Playgroud)
我制作了一个小应用程序来演示.没有java逻辑可言,但这里是布局:
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="16dp"
android:background="#caf">
<TextView
android:id="@+id/one"
android:layout_width="0dp"
android:layout_height="48dp"
android:gravity="center"
android:text="hello world"
android:background="#fff"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/two"/>
<TextView
android:id="@+id/two"
android:layout_width="0dp"
android:layout_height="48dp"
android:gravity="center"
android:text="hello world"
android:background="#eee"
app:layout_constraintTop_toBottomOf="@+id/one"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toTopOf="@+id/three"/>
<TextView
android:id="@+id/three"
android:layout_width="0dp"
android:layout_height="0dp"
android:gravity="center"
android:text="hello world"
android:background="#ddd"
app:layout_constraintHeight_default="spread"
app:layout_constraintHeight_min="300dp"
app:layout_constraintTop_toBottomOf="@+id/two"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintBottom_toBottomOf="parent"/>
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
Run Code Online (Sandbox Code Playgroud)
当底视图小于剩余的可用空间时,底视图会拉伸以填充视口,并且滚动是不可能的:
底视图在大于剩余可用空间时保持固定高度,这使得滚动成为可能:
| 归档时间: |
|
| 查看次数: |
5967 次 |
| 最近记录: |