简体   繁体   中英

Multiple LinearLayout in ScrollView

I'm stucked trying to insert multiple LinearLayout or FrameLayout (whatever..) in a ScrollView.

My structure is:

  • Activity
  • ...FragmentA
  • ...FragmentB
  • ...FragmentC

activity_layout.xml:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:fillViewport="true">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="vertical">

    <LinearLayout
        android:id="@+id/container_main"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        android:orientation="horizontal"/>

    <LinearLayout
        android:id="@+id/container_gallery"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        android:orientation="horizontal"/>

    <LinearLayout
        android:id="@+id/container_video"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        android:orientation="horizontal"/>

</LinearLayout>

One of my Fragments for example, has this layout:

<android.support.v4.view.ViewPager     xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/view_pager"
android:layout_width="match_parent"
android:layout_height="wrap_content"
tools:context="com.arbiec.conex.activities.MainActivity" />

The problem!! I can only see the 2 first fragments.

BUT when i hardcode the layout_height of the LinearLayout in my main layout (The one from the Activity) then it works just fine! But i dont want to hardcode it, because i do not know how much space will it take, it should be dynamic with wrap_content.

Any ideas?? Why could this be?

Thanks!

Try this modified layout:

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical">

   <LinearLayout
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical">

      <FrameLayout
         android:id="@+id/container_main"
         android:layout_width="match_parent"
         android:layout_height="wrap_content"
         android:background="@drawable/border"
         />

     <FrameLayout
        android:id="@+id/container_gallery"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        />

     <FrameLayout
        android:id="@+id/container_video"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@drawable/border"
        />

   </LinearLayout>

</ScrollView>

Hope this help!

Try this code...

Set below property in Scrollview

android:fillViewport="true"

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM