无法在滚动视图中滚动约束布局
Unable to scroll constraint layout inside scrollview
我正在尝试在 ScrollView 中添加约束布局,但布局不滚动
我已经尝试过的:
-> 将约束布局放入 nestedscrollview
-> 将 scrollview 放在另一个约束布局内并设置 height = "0dp", constraintTop_toTopOf = "parent", constraintTop_toTopOf = "bottom"
-> 添加 android:isScrollContainer="true"
代码如下:
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvItemName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:text="Large antique wardrobe"
android:textColor="@color/black1"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="16dp"
android:text="@string/transit_charge"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvItemName"
app:layout_constraintTop_toBottomOf="@+id/tvItemName" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="16dp"
android:text="@string/required_by"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toEndOf="@+id/textView10"
app:layout_constraintTop_toBottomOf="@+id/tvItemName" />
<TextView
android:id="@+id/tvPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/textView10"
app:layout_constraintTop_toBottomOf="@+id/textView10"
tools:text="" />
<TextView
android:id="@+id/tvRequiredByDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
android:text="dsafsadfsfdsadfasdfsadfsadf"
app:layout_constraintStart_toStartOf="@+id/textView11"
app:layout_constraintTop_toBottomOf="@+id/textView11"
tools:text="Fri · May 18" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvItemsImages"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="24dp"
android:overScrollMode="never"
app:layout_constraintEnd_toEndOf="@+id/tvItemName"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/tvPrice"
app:layout_constraintTop_toBottomOf="@+id/tvPrice">
</android.support.v7.widget.RecyclerView>
<android.support.constraint.ConstraintLayout
android:layout_width="336dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rvItemsImages">
<ImageView
android:id="@+id/imageView2"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginTop="24dp"
android:src="@drawable/shape_ring"
android:tint="@color/pickup"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:text="@string/pickup_address"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toEndOf="@+id/imageView2"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvPickupAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAllCaps="false"
android:textColor="@color/black1"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/textView19"
app:layout_constraintTop_toBottomOf="@+id/textView19" />
<TextView
android:id="@+id/tvPickupAdditionalInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAllCaps="false"
android:textColor="@color/black1"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView22"
app:layout_constraintTop_toBottomOf="@+id/textView22" />
<TextView
android:id="@+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/additional_info"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvPickupAddress"
app:layout_constraintTop_toBottomOf="@+id/tvPickupAddress" />
<TextView
android:id="@+id/textView27"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/additional_info"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvDropOffAddress"
app:layout_constraintTop_toBottomOf="@+id/tvDropOffAddress" />
<TextView
android:id="@+id/tvDropOffAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAllCaps="false"
android:textColor="@color/black1"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView24"
app:layout_constraintTop_toBottomOf="@+id/textView24" />
<TextView
android:id="@+id/tvDropOffAdditionalInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAllCaps="false"
android:textColor="@color/black1"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView27"
app:layout_constraintTop_toBottomOf="@+id/textView27" />
<TextView
android:id="@+id/textView24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/drop_off_address"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvPickupAdditionalInfo"
app:layout_constraintTop_toBottomOf="@+id/tvPickupAdditionalInfo" />
<ImageView
android:id="@+id/imageView7"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginBottom="16dp"
android:src="@drawable/shape_ring"
android:tint="@color/drop_off"
app:layout_constraintBottom_toBottomOf="@+id/tvDropOffAddress"
app:layout_constraintStart_toStartOf="parent" />
<com.capcorp.utils.DottedLine
android:id="@+id/dottedLine"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/imageView7"
app:layout_constraintEnd_toEndOf="@+id/imageView2"
app:layout_constraintStart_toStartOf="@+id/imageView2"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<TextView
android:id="@+id/tvDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginTop="32dp"
android:gravity="start"
android:text="It's a large teakwood wardrobe. Handle with care. Approx. Dimensions are 2 ft. by 4 ft"
android:textColor="@color/black1"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/tvDropOffAdditionalInfo"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvDropOffAdditionalInfo" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
-->
我正在使用以下版本的约束布局:
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
请帮忙!!!
你所做的是将第二个 ConstraintLayout
放在外面的 ConstraintLayout
里面,这没有意义,并将其高度设置为 0dp
。这样 ConstraintLayout
将自动排列此 View
以匹配 parent 大小并且内容永远不会滚动。
这里有两件事需要解决:
- 仅对根容器使用 1
ConstraintLayout
。 ConstraintLayout
本身已经 "heavy" 足以安排你的布局有很多限制。
- 不要对
ConstraintLayout
内的任何 View
使用 layout_height="0dp"
,这样 parent 的高度会扩展到包裹所有 children 的高度
我正在尝试在 ScrollView 中添加约束布局,但布局不滚动 我已经尝试过的:
-> 将约束布局放入 nestedscrollview
-> 将 scrollview 放在另一个约束布局内并设置 height = "0dp", constraintTop_toTopOf = "parent", constraintTop_toTopOf = "bottom"
-> 添加 android:isScrollContainer="true"
代码如下:
<ScrollView android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:fillViewport="true"
xmlns:android="http://schemas.android.com/apk/res/android">
<android.support.constraint.ConstraintLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<TextView
android:id="@+id/tvItemName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginLeft="24dp"
android:layout_marginRight="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="32dp"
android:text="Large antique wardrobe"
android:textColor="@color/black1"
android:textSize="24sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="0dp"
android:layout_marginStart="0dp"
android:layout_marginTop="16dp"
android:text="@string/transit_charge"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvItemName"
app:layout_constraintTop_toBottomOf="@+id/tvItemName" />
<TextView
android:id="@+id/textView11"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="48dp"
android:layout_marginTop="16dp"
android:text="@string/required_by"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toEndOf="@+id/textView10"
app:layout_constraintTop_toBottomOf="@+id/tvItemName" />
<TextView
android:id="@+id/tvPrice"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
app:layout_constraintStart_toStartOf="@+id/textView10"
app:layout_constraintTop_toBottomOf="@+id/textView10"
tools:text="" />
<TextView
android:id="@+id/tvRequiredByDate"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textColor="@color/black"
android:textSize="16sp"
android:textStyle="bold"
android:text="dsafsadfsfdsadfasdfsadfsadf"
app:layout_constraintStart_toStartOf="@+id/textView11"
app:layout_constraintTop_toBottomOf="@+id/textView11"
tools:text="Fri · May 18" />
<android.support.v7.widget.RecyclerView
android:id="@+id/rvItemsImages"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:layout_marginTop="24dp"
android:overScrollMode="never"
app:layout_constraintEnd_toEndOf="@+id/tvItemName"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="@+id/tvPrice"
app:layout_constraintTop_toBottomOf="@+id/tvPrice">
</android.support.v7.widget.RecyclerView>
<android.support.constraint.ConstraintLayout
android:layout_width="336dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginEnd="24dp"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/rvItemsImages">
<ImageView
android:id="@+id/imageView2"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginTop="24dp"
android:src="@drawable/shape_ring"
android:tint="@color/pickup"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/textView19"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="24dp"
android:layout_marginTop="8dp"
android:text="@string/pickup_address"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toEndOf="@+id/imageView2"
app:layout_constraintTop_toTopOf="parent" />
<TextView
android:id="@+id/tvPickupAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAllCaps="false"
android:textColor="@color/black1"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="@+id/textView19"
app:layout_constraintTop_toBottomOf="@+id/textView19" />
<TextView
android:id="@+id/tvPickupAdditionalInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAllCaps="false"
android:textColor="@color/black1"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView22"
app:layout_constraintTop_toBottomOf="@+id/textView22" />
<TextView
android:id="@+id/textView22"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/additional_info"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvPickupAddress"
app:layout_constraintTop_toBottomOf="@+id/tvPickupAddress" />
<TextView
android:id="@+id/textView27"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/additional_info"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvDropOffAddress"
app:layout_constraintTop_toBottomOf="@+id/tvDropOffAddress" />
<TextView
android:id="@+id/tvDropOffAddress"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAllCaps="false"
android:textColor="@color/black1"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView24"
app:layout_constraintTop_toBottomOf="@+id/textView24" />
<TextView
android:id="@+id/tvDropOffAdditionalInfo"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginEnd="8dp"
android:text="TextView"
android:textAllCaps="false"
android:textColor="@color/black1"
android:textSize="16sp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="@+id/textView27"
app:layout_constraintTop_toBottomOf="@+id/textView27" />
<TextView
android:id="@+id/textView24"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:text="@string/drop_off_address"
android:textColor="@color/colorPrimary50"
android:textSize="12sp"
app:layout_constraintStart_toStartOf="@+id/tvPickupAdditionalInfo"
app:layout_constraintTop_toBottomOf="@+id/tvPickupAdditionalInfo" />
<ImageView
android:id="@+id/imageView7"
android:layout_width="8dp"
android:layout_height="8dp"
android:layout_marginBottom="16dp"
android:src="@drawable/shape_ring"
android:tint="@color/drop_off"
app:layout_constraintBottom_toBottomOf="@+id/tvDropOffAddress"
app:layout_constraintStart_toStartOf="parent" />
<com.capcorp.utils.DottedLine
android:id="@+id/dottedLine"
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
android:layout_marginTop="8dp"
app:layout_constraintBottom_toTopOf="@+id/imageView7"
app:layout_constraintEnd_toEndOf="@+id/imageView2"
app:layout_constraintStart_toStartOf="@+id/imageView2"
app:layout_constraintTop_toBottomOf="@+id/imageView2" />
<TextView
android:id="@+id/tvDesc"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginEnd="24dp"
android:layout_marginTop="32dp"
android:gravity="start"
android:text="It's a large teakwood wardrobe. Handle with care. Approx. Dimensions are 2 ft. by 4 ft"
android:textColor="@color/black1"
android:textSize="12sp"
app:layout_constraintEnd_toEndOf="@+id/tvDropOffAdditionalInfo"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toBottomOf="@+id/tvDropOffAdditionalInfo" />
</android.support.constraint.ConstraintLayout>
</android.support.constraint.ConstraintLayout>
</ScrollView>
-->
我正在使用以下版本的约束布局:
implementation 'com.android.support.constraint:constraint-layout:1.1.0'
请帮忙!!!
你所做的是将第二个 ConstraintLayout
放在外面的 ConstraintLayout
里面,这没有意义,并将其高度设置为 0dp
。这样 ConstraintLayout
将自动排列此 View
以匹配 parent 大小并且内容永远不会滚动。
这里有两件事需要解决:
- 仅对根容器使用 1
ConstraintLayout
。ConstraintLayout
本身已经 "heavy" 足以安排你的布局有很多限制。 - 不要对
ConstraintLayout
内的任何View
使用layout_height="0dp"
,这样 parent 的高度会扩展到包裹所有 children 的高度