【问题标题】:ConstraintLayout inside ScrollView or NestedScrollView won't scrollScrollView 或 NestedScrollView 内的 ConstraintLayout 不会滚动
【发布时间】:2019-12-23 00:29:06
【问题描述】:

我是 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>

我做错了什么?

【问题讨论】:

  • 分享您的完整布局 xml
  • 你的 refresh_text 视图在哪里??

标签: android android-constraintlayout android-scrollview android-nestedscrollview


【解决方案1】:

我认为这可能是您的问题的原因:

<android.support.constraint.ConstraintLayout
     android:id="@+id/innerLayout"
     android:layout_width="match_parent"
     android:layout_height="match_parent"

滚动视图的单个子项应始终具有固定高度或wrap_content 高度。

滚动视图的想法是它们拥有一个太大而无法单独显示在屏幕上的单个子视图。如果您将单个子项定义为match_parent 高度,则无需滚动,因为子项不会大于滚动视图。

【讨论】:

  • 不行,试着把高度改成wrap_content还是不行。
猜你喜欢
  • 2022-01-02
  • 1970-01-01
  • 1970-01-01
  • 2020-04-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-10-20
  • 2020-12-23
相关资源
最近更新 更多