0

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?

Vendetta8247
  • 592
  • 1
  • 5
  • 30

3 Answers3

1

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.

Yash Sampat
  • 30,051
  • 12
  • 94
  • 120
  • Still nothing. And yes, the `LinearLayout` is the only child. I have already read a bit of questions on here as there are a lot similar but anything I've tried doesn't work... – Vendetta8247 Feb 28 '15 at 20:38
  • Just noticed that you have edited your answer. I have tried deleting everything that you told me to and it still doesn't work. I can post my whole layout if it's needed – Vendetta8247 Mar 01 '15 at 16:16
  • @Vendetta8247: i don't recall editing this, but anyhow, post a comment here to remind me when you're done posting your layout :) – Yash Sampat Mar 01 '15 at 16:35
  • strange. It seems to me that when I first looked at it it was different. Anyways, I have added the link to the question. Take a look at that. There is some cyrillic text but it's not relevant – Vendetta8247 Mar 01 '15 at 17:04
  • so far i am unable to put my finger on the problem ... try setting `fillViewPort` to `false` and use `match_parent` instead of the deprecated `fill_parent` in the `ScrollView` – Yash Sampat Mar 01 '15 at 17:08
  • without `fillViewPort` it messes up with my tile sizes. I think I know where the problem might be. In my code I change the values of every linear layout to match relative layout (One tile) width. `LinearLayout ll2 = (LinearLayout) findViewById(R.id.Linear2); RelativeLayout rl3 = (RelativeLayout) findViewById(R.id.tileLayout3); ll2.getLayoutParams().height = rl3.getLayoutParams().width;` – Vendetta8247 Mar 01 '15 at 17:18
0

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

0

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.

Ghasem
  • 14,455
  • 21
  • 138
  • 171