ScrollView无法正常工作

时间:2015-02-28 20:30:59

标签: android android-scrollview

我的布局有一些复杂的布局,它们非常大。这就是我需要ScrollView的原因。但无论我尝试什么,它都无法发挥作用。

这是我的布局文件:

    <ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        android:layout_height="match_parent"
         android:layout_width="fill_parent"
        android:fillViewport="true"
        android:layout_weight="1"
        android:orientation="vertical"
        >
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">
<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:weightSum="1">

    <LinearLayout
        android:orientation="horizontal"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_weight="0.33"
        android:id="@+id/Linear1"
        >

        <RelativeLayout
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:background="@color/tileColor1"
            android:layout_weight="1"
            android:id="@+id/tileLayout1"
            android:onClick="openFirst"
            >

我只发布了部分内容,但所有结束标记都没问题,在我的RelativeLayout内有2 textViews和一张图片。还有9个RelativeLayout具有相同的结构。

我该如何解决问题以及为什么它不起作用?它甚至没有显示滚动条。

修改

我上传了my full layout to pastebin

编辑2

在developer.android上说: You should never use a ScrollView with a ListView, because ListView takes care of its own vertical scrolling. Most importantly, doing this defeats all of the important optimizations in ListView for dealing with large lists, since it effectively forces the ListView to display its entire list of items to fill up the infinite container supplied by ScrollView.

我根本没有处理滚动问题。我想是这样的,因为我在代码中编辑LayoutParams。我该如何解决这个问题?

3 个答案:

答案 0 :(得分:1)

1。尝试删除android:layout_weight="1"android:orientation="vertical"

2. 确保ViewGroup内只有一个ScrollView(即他们所说的一个孩子)。我假设您已经完成了这项工作,但由于您尚未提供完整的布局,我无法确认。

答案 1 :(得分:0)

ScrollView只接受一个子视图。因此,将所有内容包装在LinearLayout中,并将wrap_content设置为height,然后设置。

答案 2 :(得分:0)

我有同样的问题,我不知道我的解决方案是否有帮助(主要是因为它是一个非常晚的响应),但是我的ScrollView没有用,因为设置了一个完全适合屏幕的布局,所以没有必要创建滚动。当我的布局增加时(我把所有的东西都放了 android:layout_height = WRAP_CONTENT)开始运作。

相关问题