我的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>
LinearLayoutCompat
与ScrollView
完全吻合;问题是,当我尝试以编程方式缩放LinearLayoutCompat
时,ScrollView
仍然没有开始滚动。我如何更新ScrollView
,使其滚动并显示其子视图的部分,已经走到屏幕外?
由于我没有关于如何以编程方式缩放LinearLayoutCompat
的更多细节,因此没有任何线索可以看到该部分发生了什么。
但是我注意到您将layout_width
和layout_height
设置为0dp
,这可能会更改为match_parent
或wrap_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)
}
}