当某些布局包含在ScrollView的子级中时,NestedScrollView/ScrollView不滚动


androidx.core.widget.NestedScrollView
LinearLayout
androidx.constraintlayout.widget.ConstraintLayout
TextView
CheckBox
CheckBox
CheckBox
CheckBox
CheckBox
CheckBox
CheckBox
CheckBox
CheckBox
CheckBox
TextView
include
include
include

以上是我的XML结构,当我包含布局时,滚动视图不起作用。

最初,包含的布局是"可见性GONE",当选中复选框时,这些布局将变为可见。复选框不足以使屏幕滚动,但一旦包含的布局可见,scrollView就应该滚动。但是布局在底部剪切,并且没有滚动。

完整XML:

<?xml version="1.0" encoding="utf-8"?>

<data>
<variable
name="annualRiskAssessmentVM"
type="com.cmm_android.forms.risk_assessment.AnnualRiskAssessmentVM" />
<variable
name="fragment"
type="com.cmm_android.forms.risk_assessment.AnnualRiskAssessmentFrag4" />
</data>

<androidx.core.widget.NestedScrollView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<androidx.constraintlayout.widget.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="fill_parent"
android:padding="@dimen/_16sdp">

<TextView
android:id="@+id/tv2"
style="@style/RegularBlack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_8sdp"
android:text="My support will include assistance with :"
android:textAlignment="viewStart"
app:layout_constraintTop_toBottomOf="@+id/tv1" />
<CheckBox
android:id="@+id/cbMedication"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_8sdp"
android:text="Medication"
app:layout_constraintTop_toBottomOf="@id/tv2" />
<CheckBox
android:id="@+id/cbPersonalCare"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Personal Care"
app:layout_constraintTop_toBottomOf="@id/cbMedication" />
<CheckBox
android:id="@+id/cbNutrition"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Nutrition"
app:layout_constraintTop_toBottomOf="@id/cbPersonalCare" />
<CheckBox
android:id="@+id/cbMoneyManagement"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Money Management"
app:layout_constraintTop_toBottomOf="@id/cbNutrition" />
<CheckBox
android:id="@+id/cbShopping"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Shopping"
app:layout_constraintTop_toBottomOf="@id/cbMoneyManagement" />
<CheckBox
android:id="@+id/cbSocialActivity"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Social activities or accessing the community"
app:layout_constraintTop_toBottomOf="@id/cbShopping" />
<CheckBox
android:id="@+id/cbCompanionship"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Companionship (sitter service)"
app:layout_constraintTop_toBottomOf="@id/cbSocialActivity" />
<CheckBox
android:id="@+id/cbWellbeing"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Wellbeing checks"
app:layout_constraintTop_toBottomOf="@id/cbCompanionship" />
<CheckBox
android:id="@+id/cbDomestic"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Domestic"
app:layout_constraintTop_toBottomOf="@id/cbWellbeing" />
<CheckBox
android:id="@+id/cbOther"
style="@style/CheckBox"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_4sdp"
android:text="Other"
app:layout_constraintTop_toBottomOf="@id/cbDomestic" />

<TextView
android:id="@+id/tv3"
style="@style/SmallBlack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_8sdp"
android:text="Now complete additional relevant sections below"
app:layout_constraintTop_toBottomOf="@id/cbOther" />

<include
android:id="@+id/layout_medication"
layout="@layout/layout_medication"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tv3" />
<include
android:id="@+id/layout_personal_care"
layout="@layout/layout_personal_care"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_medication" />
<include
android:id="@+id/layout_nutrition"
layout="@layout/layout_nutrition"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:visibility="gone"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/layout_personal_care" />

</androidx.constraintlayout.widget.ConstraintLayout>
</LinearLayout>
</androidx.core.widget.NestedScrollView>

我在SO上浏览了很多帖子,但没有人与包含布局的可见性有关。

所以,这是我花了一整天时间才弄清楚的最愚蠢的错误。

我的约束布局的第一个子约束到tv1的底部,它甚至不存在于整个布局中。(复制粘贴错误(

<TextView
android:id="@+id/tv2"
style="@style/RegularBlack"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="@dimen/_8sdp"
android:text="My support will include assistance with :"
android:textAlignment="viewStart"
app:layout_constraintTop_toBottomOf="@+id/tv1" />

将其更改为

app:layout_constraintTop_toTopOf="parent" 

滚动开始工作。:(

最新更新