【发布时间】:2019-07-08 20:17:25
【问题描述】:
我一直在为我的列表视图使用线性布局,如果我的数据只是像 但是当我确实想为 ConstraintLayout 格式化我的数据时,它需要一整页才能滚动,而不是像线性布局那样。
示例代码
android.support.constraint.ConstraintLayout
<TextView
android:id="@+id/textViewName"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="Name"
android:textAppearance="@style/TextAppearance.AppCompat.Large"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.019"
app:layout_constraintStart_toEndOf="@+id/textView7"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textViewNumber"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="312dp"
android:layout_marginBottom="668dp"
android:text="Number"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toEndOf="@+id/textView11"
app:layout_constraintTop_toBottomOf="@+id/textViewName"
app:layout_constraintVertical_bias="0.0" />
<TextView
android:id="@+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="8dp"
android:layout_marginTop="8dp"
android:layout_marginEnd="8dp"
android:layout_marginBottom="8dp"
android:text="July"
app:layout_constraintBottom_toBottomOf="parent"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="0.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent"
app:layout_constraintVertical_bias="0.0" />`
【问题讨论】:
-
是带bean的自定义适配器吗?
-
发布您的完整 xml 代码。
-
在 ListView 项目中使用约束布局确实是个坏主意。它会降低您的滚动性能。
-
在 UI 文件中,采用任何布局并将 ListView 标记放入其中。在以编程方式将数据绑定到 ListView 之后。无需设置任何内容即可滚动。
-
@MayurRaval 感谢您让我知道这件事。
标签: java android layout android-constraintlayout