问题:

最近在写一个程序界面,有一个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. js 事件委托代理

    在优化网页性能的技巧当中,对DOM的优化是必不可少的.这其中就涉及到了javascript对DOM的频繁操作.比如响应用户操作的事件.一般情况下,如果是稍微初级一点的前端程序员,在拿到项目的时候,对待 ...

  2. SD从零开始13-14

    SD从零开始13 使用条件记录(Working with Condition Records) 定价报表—客户特定价格Pricing Reports-customer-specific prices ...

  3. Mariadb MySQL、Mariadb中GROUP_CONCAT函数使用介绍

    MySQL.Mariadb中GROUP_CONCAT 函数使用介绍 By:授客 QQ:1033553122 语法: GROUP_CONCAT([DISTINCT] column_name [ORDER ...

  4. 构建第一个SpringBoot工程

    学习和使用 SpringBoot 有一段时间了,现在开始陆陆续续会总结归纳 SpringBoot 学习中遇到的相关知识点. SpringBoot 设计目的是用来简化新Spring应用的初始搭建以及开发 ...

  5. Git删除文件

    Git基础 Git有三大区(工作区.暂存区.版本库),文件有三个状态(untracked.unstaged.uncommited). (1)打开项目文件夹,除了隐藏的.git文件夹,其他项目文件位于的 ...

  6. IOS系统中,Web应用程序的cookie读写

    在测试项目兼容性时,发现在iphone的浏览器中,cookie的读写异常,数据一致是错误的 最后发现cookie中的value需要进行encode  = =!...... 写入cookie时,使用Ht ...

  7. 如何在linux centos 环境下运行.exe文件

    linux是不能运行window下的可执行文件的,必须借助于wine.百度了以下wine如下:   Wine (“Wine Is Not an Emulator” 的递归缩写)是一个能够在多种 POS ...

  8. windows中VirtualBox调整扩大VMDK格式的磁盘空间

    今日为了学习(zhuangX),在家中电脑上安装了VirtualBox的虚拟机,为了兼容性,选择了VMDK磁盘格式,想起办公室的电脑,在系统配置完成后,一直提示磁盘空间不足,尴尬了,重新装?环境啥的都 ...

  9. October 31st, 2017 Week 44th Tuesday

    No matter how hard the past is, you can always begin again. 不管过去有多么困难,你都可以重新开始. Honestly, I don't ag ...

  10. October 25th, 2017 Week 43rd Wednesday

    Perseverance is not a long race; it is many short races one after another. 坚持不是一个长跑,她是很多一个接一个的短跑. To ...