Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FrameLayout inside of ScrollView

Tags:

android

layout

I'm new to android development and I have the following problem. I need to use FrameLayout inside of ScrollView for making it scrollable. I wrote this

    <ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentLeft="true"
    android:layout_alignParentTop="true" 
    android:background="#00ff00">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:background="#ff0000">
    </FrameLayout>
   </ScrollView>

But this doesn't work. I tried in RelativeLayout and it worked, but I need to use for FrameLayout. Any ideas?

like image 537
nabroyan Avatar asked Mar 01 '13 16:03

nabroyan


People also ask

Can we use linear layout in ScrollView?

When adding a LinearLayout inside a ScrollView , use match_parent for the LinearLayout android:layout_width attribute to match the width of the parent ScrollView , and use wrap_content for the LinearLayout android:layout_height attribute to make it only large enough to enclose its contents.

How many views can you use within a ScrollView?

Only one view can be included in a ScrollView .

Is FrameLayout a ViewGroup?

Android Framelayout is a ViewGroup subclass that is used to specify the position of multiple views placed on top of each other to represent a single view screen.

Is ScrollView a ViewGroup?

In Android, a ScrollView is a view group that is used to make vertically scrollable views. A scroll view contains a single direct child only. In order to place multiple views in the scroll view, one needs to make a view group(like LinearLayout) as a direct child and then we can define many views inside it.


3 Answers

To get FrameLayout inside ScrollView, do this:

<ScrollView
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_below="@+id/linearLayoutHeader1"
    android:layout_centerHorizontal="true" >

    <LinearLayout
        android:id="@+id/LinearLayout1"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <FrameLayout
            android:id="@+id/FrameLayout1"
            android:layout_width="match_parent"
            android:layout_height="1440dp"
             >
        </FrameLayout>

    </LinearLayout>
</ScrollView>
like image 193
Sumoanand Avatar answered Nov 03 '22 04:11

Sumoanand


android:fillViewport="true" solves this issue.

android:fillViewport, Defines whether the scrollview should stretch its content to fill the viewport.

    <ScrollView
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fillViewport="true">

    <FrameLayout
        android:id="@+id/frameLayout"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">
    </FrameLayout>
   </ScrollView>
like image 40
Sreedhu Madhu Avatar answered Nov 03 '22 04:11

Sreedhu Madhu


I tried many variants for solving this problem, including answers here, but no one was helpful. ScrollView always wraps FrameLayout, but everything is normal with RelativeLayout, LinearLayout...

I have found one solution for this - to set minimum height of FrameLayout. You can set dynamically minimum height by setMinimumHeight() method.

like image 6
nabroyan Avatar answered Nov 03 '22 03:11

nabroyan