[英]ConstraintLayout inside ScrollView or NestedScrollView won't scroll
我對ConstraintLayout相當陌生,並嘗試將UI轉換為自適應布局以支持不同的屏幕尺寸。 但是,當內部布局為ConstraintLayout時,我的ScrollView滾動出現了麻煩。 即使當我將ScrollView更改為NestedScrollView時,它仍然不會滾動。 我嘗試了幾種解決方案,其中許多提出了相同的問題,但似乎都沒有奏效。
<android.support.v4.widget.NestedScrollView
android:id="@+id/list"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="5dp"
android:fillViewport="true"
app:layout_constrainedHeight="true"
app:layout_constraintBottom_toTopOf="@+id/logo"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintTop_toBottomOf="@+id/refresh_text">
<android.support.constraint.ConstraintLayout
android:id="@+id/innerLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<android.support.constraint.ConstraintLayout
android:id="@+id/innerLayout2"
android:layout_width="0dp"
android:layout_height="0dp"
android:background="@color/light_gray"
app:layout_constraintBottom_toTopOf="@+id/key_constraint_layout"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHeight_percent=".1"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<TextView
android:id="@+id/status_date_text"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:gravity="center_vertical"
android:layout_marginTop="5dp"
android:layout_marginBottom="5dp"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="Status Date"
android:textSize="20sp"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/status_date_value"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:paddingStart="10dp"
android:paddingEnd="10dp"
android:text="-------"
android:gravity="end|center_vertical"
android:textSize="20sp"
app:layout_constrainedHeight="true"
app:layout_constrainedWidth="true"
app:layout_constraintHorizontal_bias="0.70"
app:layout_constraintLeft_toLeftOf="parent"
app:layout_constraintRight_toRightOf="parent"
app:layout_constraintTop_toTopOf="parent" />
</android.support.constraint.ConstraintLayout>
<!--Other inner layouts are children of innerLayout based on innerLayout2 -->
</android.support.constraint.ConstraintLayout>
<android.support.v4.widget.NestedScrollView>
我究竟做錯了什么?
這可能是導致您出現問題的原因:
<android.support.constraint.ConstraintLayout android:id="@+id/innerLayout" android:layout_width="match_parent" android:layout_height="match_parent"
滾動視圖的單個子代應始終具有固定高度或wrap_content
高度。
滾動視圖的想法是,它們容納的單個孩子太大,無法單獨顯示在屏幕上。 如果將單個孩子定義為match_parent
高度,則沒有任何可滾動的內容,因為該孩子不大於滾動視圖。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.