问题:

最近在写一个程序界面,有一个scrollVIew,其中有一段内容是需要在线加载的。

当内容加载完成后,ScrollView中内容的长度会发生改变,这时ScrollView会自动下滚,如下图所示:

滚动的那一下体验特别不好,所以要防止这种情况。即不论Scrollview中内容如何,都要保持在最上。

解决办法:

先简单写一下我的xml文件的结构:

  1. <ScrollView
  2. android:id="@+id/scrollView1"
  3. android:layout_width="fill_parent"
  4. android:layout_height="fill_parent"
  5. android:layout_alignParentLeft="true"
  6. android:layout_below="@+id/linearLayout2"
  7. android:background="@drawable/repeat_bg"
  8. android:paddingBottom="5dp" >
  9. <LinearLayout
  10. android:layout_width="match_parent"
  11. android:layout_height="match_parent"
  12. android:orientation="vertical"
  13. android:paddingLeft="10dp"
  14. android:paddingRight="10dp"
  15. android:focusable="true"
  16. android:focusableInTouchMode="true"
  17. android:paddingTop="15dp" >
  18. <!-- 上面这两行是控制scrollview
  19. android:focusable="true"
  20. android:focusableInTouchMode="true"
  21. 不自动的关键! !-->
  22. <LinearLayout
  23. android:layout_width="match_parent"
  24. android:layout_height="wrap_content"
  25. android:orientation="vertical" >
  26. <ListView
  27. android:id="@+id/lv_gc"
  28. android:layout_marginTop="5dp"
  29. android:layout_width="match_parent"
  30. android:layout_height="20dp"
  31. android:background="#aaffffff"
  32. android:divider="#666"
  33. android:scrollbars="none|vertical" >
  34. </ListView>
  35. </LinearLayout>
  36. </LinearLayout>
  37. </ScrollView>

如上面代码,我的ScrollView中第一个内容是LinearLayout,下面有一个LinearLayout包裹着的ListView.ListView是长度可变的。

将LinearLayout中加入代码:

  1. android:focusable="true"
  2. android:focusableInTouchMode="true"

问题即可解决,欢迎大家交流。

转载请注明来自:http://blog.csdn.net/icyfox_bupt/article/details/15026299

解决Android中,禁止ScrollView内的控件改变之后自动滚动 - 转的更多相关文章

  1. 解决Android中,禁止ScrollView内的控件改变之后自动滚动

    <ScrollView android:id="@+id/scrollView1" android:layout_width="fill_parent" ...

  2. 解决tableView中cell动态加载控件的重用问题

    解决tableView中cell动态加载控件的重用问题 tableView的cell,有时候需要在运行时取得对应的数据后才能够动态的创建该cell中的控件并加载到该cell中,此时,你一定会遇到重用问 ...

  3. 【转】android中最好的瀑布流控件PinterestLikeAdapterView

    [源地址]http://www.jcodecraeer.com/a/anzhuokaifa/androidkaifa/2014/0919/1696.html 之前我们介绍过一个开源的瀑布流控件Stag ...

  4. [转]android中最好的瀑布流控件PinterestLikeAdapterView

    PinterestLikeAdapterView 项目地址:https://github.com/GDG-Korea/PinterestLikeAdapterView 使用方法类似于ListView下 ...

  5. android中与Adapter相关的控件----ListView

    ListView讲解: 一.ListView这个控件是一个使用非常广泛的控件,值得深入的学习和研究.基本使用已经在Adapter中使用过了 二.常用的属性和方法 footerDividersEnabl ...

  6. Android中EditText,Button等控件的设置

    EditText可以使用:TextView.setEnabled(true)来设置为可编辑,其实很简单,写在这里以便以后自己查看. Button设置可用性:setVisibility(View.VIS ...

  7. android中与Adapter相关的控件----GridView

    GridView(网格视图)讲解 一.GridView(网格视图)这个是控件也是比较多,和listView的很多地方都是一样的,但是GridView可以显示多列,而listView只能显示一列,个人觉 ...

  8. android中与Adapter相关的控件----ViewFlipper

    ViewFlipper(翻转视图) 一.ViewFlipper是一个多页面管理的控件,与ViewPager不同,ViewPager的是一页一页的的,而ViewFlipper则是一层一层的.图片轮播或者 ...

  9. Android文字跑马灯控件(文本自动滚动控件)

    最近在开发一个应用,需要用到文本的跑马灯效果,图省事,在网上找,但老半天都找不到,后来自己写了一个,很简单,代码如下: import android.content.Context; import a ...

随机推荐

  1. React之设置元素的滚动条

    在React中,解耦了对DOM元素的操作,但有时我们确实需要对DOM操作,比如设置元素的滚动条,这时ref就满足了我们的需求 在低版本的react中,ref可以是一个string类型的属性,通过thi ...

  2. css 单行/多行文字垂直居中问题

    例子可以直接看这里http://www.zhangxinxu.com/study/200911/line-height-text-v-center.html 这篇文章中有一点点解释http://blo ...

  3. [性能调优]在PeopleSoft中使用函数索引

    那些没有在PeopleSoft系统遇到性能问题的人,特别是基于Oracle数据库的PeopleSoft,可能不知道基于函数的索引. 根据定义,基于函数的索引是使用如下方法定义的: 基于表达式,例如算术 ...

  4. FineReport连接多维数据库示例及操作

    1. 描述 FineReport连接多维数据库,首先要通过数据连接将多维数据库与FineReport连接起来,然后在数据连接的基础上新建多维数据库XMLA数据集,用于模板设计. 2.XMLA数据连接 ...

  5. Android GetMethodID 函数的说明

    GetFieldID是得到java类中的参数ID,GetMethodID得到java类中方法的ID,它们只能调用类中声明为 public的参数或方法.使用如下: jfieldID topicField ...

  6. Python网络爬虫笔记(四):使用selenium获取动态加载的内容

    (一)  说明 上一篇只能下载一页的数据,第2.3.4....100页的数据没法获取,在上一篇的基础上修改了下,使用selenium去获取所有页的href属性值. 使用selenium去模拟浏览器有点 ...

  7. Python+Selenium笔记(五):生成测试报告

    #HTMLTestRunner代码修改参考 微微微笑 的说明,下面是链接,这个已经说的很详细了 https://www.cnblogs.com/miniren/p/5301081.html (一) 前 ...

  8. python中pip

    经常在安装软件过程中用pip 安装,当时的我总觉得pip是给linux还有mac用的,所以就从没有仔细研究过pip,后来用了python才知道pip这么好用 今天总结一下pip的用法 我的电脑是win ...

  9. 查询es curl命令记录

    curl  -H "Content-Type: application/json" -XGET http://10.65.0.33:9200/online/senseLog/_se ...

  10. [钉钉通知系列]SVN提交后自动推送消息到钉钉群

    钉钉设置机器人配置 1.进入配置机器人入口 2.添加机器人 3.测试WebHook请求 本人使用Postman进行测试 4.配置SVN 4.1 配置 Pre-commit hook 设置提交内容必须包 ...