在我的 Android 应用程序中,我有一个活动,其中包含以下组件,包含在ConstraintLayout
(all width=match_parent
, height=wrap_content
) 中:
title
scrollview
linearLayout
fragment1
fragment2
fragment3
fragment4
adUnit
我希望 title 和 adUnit 保持固定,其余部分垂直滚动。我或多或少地发生了这种情况,但片段不再显示它们的所有内容——我认为它们都被设置为相同的高度。我如何在这里实现我想要的?
这是我当前的布局(精简到相关部分):
<android.support.constraint.ConstraintLayout
android:layout_height="match_parent"
android:layout_width="match_parent">
<TextView
android:id="@+id/tv_title"
android:layout_width="0dp"
android:layout_height="wrap_content"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<android.support.v4.widget.NestedScrollView
android:layout_width="0dp"
android:layout_height="0dp"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toTopOf="@+id/adView"
app:layout_constraintTop_toBottomOf="@id/tv_title">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<fragment
android:id="@+id/fragment_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toTopOf="parent"
tools:layout="@layout/fragment_1" />
<fragment
android:id="@+id/fragment_2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/fragment_1"
tools:layout="@layout/fragment_2" />
<fragment
android:id="@+id/fragment_3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/fragment_2"
tools:layout="@layout/fragment_3" />
<fragment
android:id="@+id/fragment_4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
app:layout_constraintTop_toBottomOf="@id/fragment_3"
tools:layout="@layout/fragment_4" />
</android.support.constraint.ConstraintLayout>
</android.support.v4.widget.NestedScrollView>
<include
android:id="@+id/adView"
layout="@layout/layout_ad_view"
android:layout_width="0dp"
android:layout_height="50dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent" />
</android.support.constraint.ConstraintLayout>