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?
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.
Only one view can be included in a ScrollView .
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.
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.
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>
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With