本文介绍了滚动型不滚动到顶部的线性布局的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有没有所有的方式滚动时,我向上滚动屏幕上方一个相当简单的滚动视图。
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>
推荐答案
您好我有同样的问题,并调查后,我已经找到了解决方案,并在你的XML code,我可以看到你正在做同样的错误的布局。
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.
问题是,您正在设置滚动型子(LinearLayout中)布局重力中心。删除此行,它应该为你工作。
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
这篇关于滚动型不滚动到顶部的线性布局的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!