Vendetta8247
Vendetta8247

Reputation: 601

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?

Upvotes: 0

Views: 1908

Answers (3)

user5754460
user5754460

Reputation: 1

I had the same problem, and I do not know if my solution helped (mainly because it is a very late response), but my ScrollView not worked since set up a layout that fit exactly on the screen, so it was not necessary to create scrolling. When increased my layout (I put all my items with android:layout_height = WRAP_CONTENT) became operational.

Upvotes: 0

Yash Sampat
Yash Sampat

Reputation: 30611

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.

Upvotes: 1

user2154462
user2154462

Reputation:

ScrollView only accepts one child view. So wrap everything inside it in a LinearLayout with wrap_content set as height and you're set.

Upvotes: 0

Related Questions