Android中,线性布局无法滚动

4

我对Android编程相对较新。有人能告诉我为什么我的ScrollView无法滚动吗?

我的活动已实现OnGestureListener以获取某些触摸信息。但是,我尝试禁用onGestureListener,它仍然无法工作。

它在SlidingDrawer之外可以工作。是否可能使其在SlidingDrawer内工作?

我通过为ScrollView提供ID,然后将该ID放入SlidingDrawer android:content="@+id/content"中来解决此问题。

    <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="right"
        android:background="@drawable/pozadina_touchpad"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="100dp"
            android:layout_height="match_parent"
            android:layout_gravity="right"
            android:orientation="vertical" >

            <SlidingDrawer
                android:id="@+id/prosirenje"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:orientation="horizontal"
                android:content="@+id/content"
                android:handle="@+id/handle" >

                <Button
                    android:id="@+id/handle"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:background="@drawable/gumb_slider"
                     />

                <ScrollView
                android:layout_width="fill_parent"
                android:layout_height="wrap_content">

                    <LinearLayout
                        android:id="@+id/content"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"
                        android:background="@drawable/slider"
                        android:gravity="center"
                        android:onClick="nemaSkrola"
                        android:orientation="vertical" >

                        <Button
                            android:id="@+id/ico_povecalo"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="20dp"
                            android:background="@drawable/ikona_povecalo" />

                        <Button
                            android:id="@+id/ico_desktop"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="20dp"
                            android:background="@drawable/ikona_komp" />

                        <Button
                            android:id="@+id/ico_daljinski"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="20dp"
                            android:background="@drawable/ikona_play" />

                        <Button
                            android:id="@+id/ico_tipkovnica"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="20dp"
                            android:background="@drawable/ikona_tipka" />

                        <Button
                            android:id="@+id/ico_settings"
                            android:layout_width="wrap_content"
                            android:layout_height="wrap_content"
                            android:layout_margin="20dp"
                            android:background="@drawable/ikona_settings" />

                    </LinearLayout>

                </ScrollView>

            </SlidingDrawer>

        </LinearLayout>

    </LinearLayout>

尝试移除 android:onClick="nemaSkrola",看看是否会有任何不同。 - Slickelito
尝试在您的父LinearLayout中添加以下内容: android:fillViewport="true" android:scrollbars="vertical",并在ScrollView中添加以下内容 android:fillViewport="true" android:layout_height="fill_parent" - v0d1ch
谢谢大家,但还是没有任何进展。 - jpetrucci
2个回答

2

给scrollView的宽度和高度赋值,并尝试像这样操作

<ScrollView
    android:id="@id/content"
    android:layout_width="300dp"
    android:layout_height="300dp"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="15dp">
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
    </LinearLayout>
</ScrollView>

请将ScrollView的id更改为以下内容:
android:id="@id/content"

请将操作按钮的id修改为以下内容:

android:id="@id/handle"

1

ScrollView的容器(层级父元素)具有以下属性设置:android:layout_height="match_parent",这将强制它们将其内容限制为活动(屏幕)的高度。
为了使您的ScrollView正常工作,请尝试将ScrollView提升到更高的层次结构中,以便不受其父元素的限制。


那个可以运行...但是如果我把ScrollView放在SlidingDrawer里面,它就不能工作了...有可能让它在SlidingDrawer中工作吗? - jpetrucci

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接