android–Scrollview没有在线性布局中滚动到顶部

android–Scrollview没有在线性布局中滚动到顶部,第1张

概述我有一个相当简单的滚动视图,当我向上滚动时,它不会一直滚动到屏幕顶部.<?xmlversion="1.0"encoding="utf-8"?><LinearLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:myapp="http://schemas.android.com/apkes/com.

我有一个相当简单的滚动视图,当我向上滚动时,它不会一直滚动到屏幕顶部.

 <?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代码中,我可以看到你在布局中犯了同样的错误.

问题是您将ScrollVIEw子(linearLayout)布局重力设置为居中.删除此行,它应该适合您.

androID:layout_gravity="center"   //remove this line
总结

以上是内存溢出为你收集整理的android – Scrollview没有在线性布局中滚动到顶部全部内容,希望文章能够帮你解决android – Scrollview没有在线性布局中滚动到顶部所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1111644.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存