FrameLayout inside of ScrollView

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?

  • Call to `getDrawingCache` returns null when scroll is enabled
  • Android 3.1 soft keyboard in fullscreen mode
  • Quota limits for YouTube Android Player API
  • create script in Cordova fails with unexpected error in Ubuntu 12.10
  • Does ImageView.setImageURI(Uri uri) work with remote files?
  • How to set up my personal keyboard as standard input in my app
  • Related posts:

    Android. Fragment getActivity() sometimes returns null
    Broadcasts are delayed
    How does the Android Market work for developers?
    Error: This Android SDK requires Android Developer Toolkit version 22.6.1 or above
    ADB not responding. You can wait more, or kill &ldquo;adb.exe&rdquo; &hellip; windows 8
    Sending a GCM message (server-side) often fails - but far from always
  • WiFi lock doesn't work, how to prevent wifi power save?
  • How do you get/set media volume (not ringtone volume) in Android?
  • Code Path per Flavor in Android Gradle
  • Any iOS Storyboard equivalent for Android development?
  • Publishing Android Library (aar) to Bintray with chosen flavors
  • integrate facebook with like button in android and iphone
  • 5 Solutions collect form web for “FrameLayout inside of ScrollView”

    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>
    

    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.

    Your xml sample is quite good, the only thing I can see is : if the ScrollLayout parent is bigger than 500dp it won’t scroll.

    Indeed, the scroll is used only if the content is bigger than the scrollview.

    here, you set your content height to 500dip and you scrollview to ‘match_parent’
    if the parent of this scrollView take the whole screen, on a 800dip height screen (for example)

    => the scroll is simply not needed.

    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>
    

    Try setting layout_height to “wrap_content” in your FrameLayout

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

    It will scroll when the FrameLayout will be higher than the screen border. Or if you want the fixed height of scrollable area, set height to 500dp on ScrollView. It depends what you want, but don’t ever set the fixed height on a ScrollView child. The ScrollView child’s height should always be wrap_content.

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_width="match_parent"
        android:layout_height="500dp"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true" 
        android:background="#00ff00">
    
        <FrameLayout
            android:id="@+id/frameLayout"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:background="#ff0000">
        </FrameLayout>
    </ScrollView>
    
    Android Babe is a Google Android Fan, All about Android Phones, Android Wear, Android Dev and Android Games Apps and so on.