NestedScrollView/ 当某些布局包含到 ScrollView 的子级时,ScrollView 不滚动
NestedScrollView/ ScrollView is not scrolling when some layout are included to the child of 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 的结构,当我包含布局时,滚动视图不工作。
最初包含的布局是 Visibility 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 的帖子,但没有一个与包含的布局的可见性相关。
所以,这是我花了一整天才弄明白的最愚蠢的错误。
我的约束布局的第一个 child 被限制在 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"
卷轴开始工作了。 :)
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 的结构,当我包含布局时,滚动视图不工作。
最初包含的布局是 Visibility 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 的帖子,但没有一个与包含的布局的可见性相关。
所以,这是我花了一整天才弄明白的最愚蠢的错误。
我的约束布局的第一个 child 被限制在 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"
卷轴开始工作了。 :)