简体   繁体   English

当其子视图按比例放大时,ScrollView 不会滚动

[英]ScrollView doesn't scroll when its child view is scaled up

I have a LinearLayoutCompat inside my 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>

The LinearLayoutCompat fits inside the ScrollView perfectly; LinearLayoutCompat完全适合ScrollView the problem is that when I try to scale up the LinearLayoutCompat programmatically, the ScrollView still doesn't start scrolling.问题是,当我尝试以编程方式放大LinearLayoutCompat时, ScrollView仍然没有开始滚动。 How can I update the ScrollView so that it scrolls and shows the parts of its child view that have gone outside the screen?我如何更新ScrollView以便它滚动并显示屏幕外的子视图部分?

Since I don't have more detail about how you scale up the LinearLayoutCompat programmatically, so there is no any clues to see what's going on for that part.由于我没有关于如何以编程方式扩展LinearLayoutCompat的更多详细信息,因此没有任何线索可以了解该部分发生了什么。

However I notice that you set the layout_width and layout_height as 0dp , which maybe can change to match_parent or wrap_content .但是我注意到您将layout_widthlayout_height设置为0dp ,这可能会更改为match_parentwrap_content

Here is a snapshot of code which I add the ImageView into LinearLayoutCompat programmatically to mimic the scale up and the scrollview can be scrolled这是代码的快照,我以编程方式将ImageView添加到LinearLayoutCompat中以模拟放大并且可以滚动滚动视图

<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)
    }
} 

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM