Search code examples
androidandroid-scrollview

ScrollView doesn't work


My Layout has a few complex layouts and they are pretty big. That's why I need a ScrollView. But whatever I try it doesn't work.

Here is my layout file:

    <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"
            >

I have only posted a part of it but all the closing tags are ok and inside my RelativeLayout there are 2 textViews and an image. There are 9 more RelativeLayouts with the same structure.

How can I fix the problem and why doesn't it work? It doesn't even show a scrollbar.

EDIT

I have uploaded my full layout to pastebin

EDIT 2

On the developer.android it is said: 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.

Mine doesn't deal with the scrolling at all. I suppose it is this way because I edit LayoutParams in code. How do I fix this?


Solution

  • 1. Try removing android:layout_weight="1" and android:orientation="vertical".

    2. Ensure that there is only one ViewGroup inside the ScrollView (i.e. one child as they say). I assume you've done this, but as you haven't provided your full layout I couldn't confirm it.