Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scrollview not scrolling to the top in a linear layout

I have a fairly simple scrollview that is not scrolling all the way to the top of the screen when i scroll up.

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout 
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:myapp="http://schemas.android.com/apk/res/com.surreall.matchit"
    xmlns:ads="http://schemas.android.com/apk/lib/com.google.ads" 

    android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="fill_parent"
    android:background="@drawable/background"
    android:id="@+id/main_layout2"
    >

<ScrollView
    android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

    <LinearLayout
            android:orientation="vertical"
            android:layout_width="wrap_content"
            android:layout_height="0dp"
            android:layout_marginTop="1dp"
            android:layout_gravity="center" 
            android:id="@+id/board"
            android:layout_weight="6"
            android:baselineAligned="false"

            >     
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1" 
            >

            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card1"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>

            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card2"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card3"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card4"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>

            </LinearLayout>  
       <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center" 
            android:layout_weight="1"
            >
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card5"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>

            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card6"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
           <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card7"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card8"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>       
            </LinearLayout> 
       <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content" 
            android:layout_weight="1"
            android:layout_gravity="center" 
            >
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card9"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card10"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card11"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card12"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>       
            </LinearLayout>
        <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            >
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card13"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card14"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card15"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card16"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>       
            </LinearLayout>
            <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            >
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card17"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card18"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card19"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card20"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>       
            </LinearLayout>
            <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            >
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card21"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card22"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card23"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card24"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>       
            </LinearLayout>
            <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            >
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card25"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card26"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card27"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card28"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>       
            </LinearLayout>
            <LinearLayout
            android:orientation="horizontal"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_gravity="center"
            android:layout_weight="1"
            >
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card29"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card30"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card31"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>
            <com.surreall.logo.SquareButton         
                android:layout_height="fill_parent"
                android:layout_width="0dip"          
                android:layout_weight="1"  >        
                <ImageView
                android:id="@+id/card32"
                android:layout_gravity="center"
                android:adjustViewBounds="true"
                android:scaleType="centerInside"
                android:layout_height="wrap_content"
                android:layout_width="0dp"          
                android:layout_weight="1" 
                android:layout_margin="4dp"
                /> </com.surreall.logo.SquareButton>       
            </LinearLayout>
     </LinearLayout> 
 </ScrollView>
</LinearLayout>

Looks like this

like image 861
clayton33 Avatar asked Dec 26 '22 19:12

clayton33


1 Answers

Hi I had the same problem, and after investigation I have found the solution, and in your XML code I can see that you are doing the same mistake in layout.

The problem is that you are setting the ScrollView child (LinearLayout) layout gravity to center. Remove this line and it should work for you.

android:layout_gravity="center"   //remove this line
like image 160
user3098756 Avatar answered Jan 10 '23 06:01

user3098756