Android: My LinearLayout expands out of its parent scrollview

1.1k Views Asked by At

Can anyone help me with this piece of xml code here is a print screen: http://flic.kr/p/fKEqmn

Here is my xml code:

    <ScrollView
    android:id="@+id/scrollView1"
    android:layout_marginTop="40dp"

    android:layout_width="match_parent"
    android:layout_height="match_parent" >

   <LinearLayout
   android:id="@+id/LinearLayoutmain"
    android:clipToPadding="true"
   android:layout_width="fill_parent"
   android:layout_height="match_parent"
   android:layout_marginTop="10dp"
   android:orientation="vertical"
   android:scaleType="fitXY" >

    <LinearLayout
    android:id="@+id/LinearLayout01"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginLeft="20dp"
    android:layout_marginTop="10dp"
    android:orientation="vertical" >

        <ImageButton
        android:id="@+id/pd"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="60dp"
        android:onClick="pod"
        android:scaleType="fitXY"
        android:src="@drawable/podcast" />

        <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Podcast section is where students can access voice   " />

        <ImageButton
        android:id="@+id/an"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="announce"
        android:scaleType="fitXY"
        android:src="@drawable/announce" />

         <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.News section contains announcements posted by instructors" />

        <ImageButton
        android:id="@+id/ex"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="eksam"
        android:scaleType="fitXY"
        android:src="@drawable/exam" />

         <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Exam section contains the schedule of examinations" />

        <ImageButton
        android:id="@+id/kl"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="kalendaryo"
        android:scaleType="fitXY"
        android:src="@drawable/calendar" />

        <TextView
        android:id="@+id/textView4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Calendar section has the schedule of different University " />

        <ImageButton
        android:id="@+id/cl"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="klas"
        android:scaleType="fitXY"
        android:src="@drawable/klase" />

        <TextView
        android:id="@+id/textView5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Class section contains the users different class schedules" />

       <ImageButton
        android:id="@+id/gr"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="grupo"
        android:scaleType="fitXY"
        android:src="@drawable/group" />

        <TextView
        android:id="@+id/textView6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Groups section lists all the groups that the user belongs"  />

        <ImageButton
         android:id="@+id/lc"
         android:layout_width="50dp"
         android:layout_height="wrap_content"
         android:layout_marginLeft="110dp"
         android:layout_marginRight="20dp"
         android:layout_marginTop="10dp"
         android:adjustViewBounds="true"
         android:background="@null"
         android:maxHeight="30dp"
         android:maxWidth="50dp"
         android:onClick="lectures"
         android:scaleType="fitXY"
         android:src="@drawable/lec" />

        <TextView
         android:id="@+id/textView7"
         android:layout_width="wrap_content"
         android:layout_height="wrap_content"
         android:layout_marginTop="10dp"
         android:text="My.Lectureshare contains files that were posted by the       />

        <ImageButton
         android:id="@+id/post"
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:layout_marginLeft="110dp"
        android:layout_marginRight="20dp"
        android:layout_marginTop="10dp"
        android:adjustViewBounds="true"
        android:background="@null"
        android:maxHeight="30dp"
        android:maxWidth="50dp"
        android:onClick="lecpost"
        android:scaleType="fitXY"
        android:src="@drawable/post" />

     <TextView
        android:id="@+id/textView8"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginTop="10dp"
        android:text="My.Post is were instructors are capable to post files  class" />

     </LinearLayout>





      </LinearLayout>


     </ScrollView>

So basically I want the linearlayout to fit inside its parent scroll view.. I already set its height to match_parent but still it goes out of bounds

2

There are 2 best solutions below

1
On

A scrollview is designed to have content that exceeds the height of the screen, thus making it scrollable. I assume that is why you use a scrollview in the first place.

If you want to be able to see all of your child LinearLayout in your designer, you can change the device view from Nexus S (which it is set to in your screenshot) and choose for instance a 10.1 tablet view. This will not affect how the design looks on your phone, it will just give you more screen space to design on.

1
On
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollView1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:padding="5dp" >

    <LinearLayout
        android:id="@+id/LinearLayout01"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:orientation="vertical" >

        <ImageButton
            android:id="@+id/pd"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="60dp"
            android:onClick="pod"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView1"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Podcast section is where students can access voice   " />

        <ImageButton
            android:id="@+id/an"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="announce"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView2"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.News section contains announcements posted by instructors" />

        <ImageButton
            android:id="@+id/ex"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="eksam"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView3"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Exam section contains the schedule of examinations" />

        <ImageButton
            android:id="@+id/kl"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="kalendaryo"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView4"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Calendar section has the schedule of different University " />

        <ImageButton
            android:id="@+id/cl"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="klas"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView5"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Class section contains the users different class schedules" />

        <ImageButton
            android:id="@+id/gr"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="grupo"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView6"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Groups section lists all the groups that the user belongs" />

        <ImageButton
            android:id="@+id/lc"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="lectures"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView7"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:onClick="lecpost"
            android:text="My.Lectureshare contains files that were posted by the" />

        <ImageButton
            android:id="@+id/post"
            android:layout_width="50dp"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:adjustViewBounds="true"
            android:maxHeight="30dp"
            android:maxWidth="50dp"
            android:onClick="lecpost"
            android:scaleType="fitXY"
            android:src="@drawable/ic_launcher" />

        <TextView
            android:id="@+id/textView8"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginTop="5dp"
            android:text="My.Post is were instructors are capable to post files  class" />
    </LinearLayout>

</ScrollView>

// this my out put
![enter image description here][1]