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的结构,当我包括布局时,scrollview不起作用。
最初,所包含的布局为“可见性已消失”,选中此复选框后,它们将变为可见。 复选框不足以使屏幕可滚动,但是一旦使包含的布局可见,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上发表了许多文章,但是没有人涉及所包含布局的可见性。
答案 0 :(得分:0)
所以,这是我一整天都想出的最愚蠢的错误。
我的约束布局的第一个孩子被约束在tv1的底部,而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"
,滚动开始工作。 :)