ScrollView 在其子视图放大时不会滚动



我的ScrollView里面有一个LinearLayoutCompat:

<ScrollView
android:layout_width="0dp"
android:layout_height="0dp"
android:layout_marginBottom="8dp"
app:layout_constraintBottom_toTopOf="@id/overview_holder"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/seats_viewHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>

LinearLayoutCompatScrollView完全吻合;问题是,当我尝试以编程方式缩放LinearLayoutCompat时,ScrollView仍然没有开始滚动。我如何更新ScrollView,使其滚动并显示其子视图的部分,已经走到屏幕外?

由于我没有关于如何以编程方式缩放LinearLayoutCompat的更多细节,因此没有任何线索可以看到该部分发生了什么。

但是我注意到您将layout_widthlayout_height设置为0dp,这可能会更改为match_parentwrap_content

这是我以编程方式将ImageView添加到LinearLayoutCompat中的代码快照,以模拟缩放,scrollview可以滚动

<ScrollView
android:id="@+id/scrollview"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginBottom="8dp"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<androidx.appcompat.widget.LinearLayoutCompat
android:id="@+id/seats_viewHolder"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical" />
</ScrollView>
override fun onCreate(savedInstanceState: Bundle) {
val linearLayoutCompat = findViewById<LinearLayoutCompat>(R.id.seats_viewHolder)
for (i in 0 .. 100) {
val imageView = ImageView(this).apply {
setImageResource(R.drawable.ic_launcher_background)
}
linearLayoutCompat.addView(imageView)
}
} 

最新更新