简体   繁体   English

包含linearlayout的滚动视图不起作用

[英]Scroll view containing linearlayouts don't work

Why my scroll view doesn't scroll? 为什么我的滚动视图不滚动?

Here are my xml: 这是我的xml:

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="@android:color/white" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_marginBottom="20dip"
        android:layout_marginTop="20dip"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip" >

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b1"
                android:onClick="b1" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b2"
                android:onClick="b2" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b3"
                android:onClick="b3" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b4"
                android:onClick="b4" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/b5"
                android:onClick="b5" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip" >

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b6"
                android:onClick="b6" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b7"
                android:onClick="b7" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b8"
                android:onClick="b8" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b9"
                android:onClick="b9" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/b10"
                android:onClick="b10" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip" >

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b11"
                android:onClick="b11" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b12"
                android:onClick="b12" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b13"
                android:onClick="b13" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b14"
                android:onClick="b14" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/b15"
                android:onClick="b15" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip" >

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b16"
                android:onClick="b16" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b17"
                android:onClick="b17" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b18"
                android:onClick="b18" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b19"
                android:onClick="b19" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/b20"
                android:onClick="b20" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="80dip"
            android:layout_marginLeft="10dip"
            android:layout_marginRight="10dip"
            android:layout_marginTop="10dip" >

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b21"
                android:onClick="b21" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b22"
                android:onClick="b22" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b23"
                android:onClick="b23" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_marginRight="5dip"
                android:layout_weight="1"
                android:background="@drawable/b24"
                android:onClick="b24" />

            <Button
                android:layout_width="0dip"
                android:layout_height="wrap_content"
                android:layout_weight="1"
                android:background="@drawable/b25"
                android:onClick="b25" />
        </LinearLayout>
    </LinearLayout>

</ScrollView>

Any idea? 任何想法?

ScrollView cannot hold more than 1 child.. it needs 1 single child which hosts all other view.. Hope this help you ScrollView不能容纳超过1个孩子。它需要1个单独的孩子来承载所有其他视图。希望这对您有所帮助

<ScrollView>
<LinearLayout
android:id="@+id/child">
<ImageView/>
</LinearLayout>
</ScrollView>

Everything works fine, you just have not enough buttons to enable scrolling(you don't need it). 一切正常,您没有足够的按钮来启用滚动(不需要)。
For see how scrolling works, use less screen size, or add more Linearlayouts with buttons . 要了解滚动的工作方式,请使用较小的屏幕尺寸,或使用buttons添加更多的Linearlayouts

我不确定它是否有效,但是您也可以尝试将android:scrollbars =“ vertical”属性添加到LinearLayout中

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

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