Android,ScrollView内的控件改变之后禁止自动滚动

    在android的实际开发中,会要这样的情况。就是scrollView布局中,嵌套了很多布局,但是ScrollView的布局里面只能嵌套一个大的布局,而大的布局中在嵌套各种其他的布局!
    可是,实际中,如ScrollView中的大的布局中嵌套了一个ListView布局,当ListView中的数据进行更新后,ScrollView就会自动滚动了!非常影响实际使用。那么如何解决呢?其实很简单!就两步!
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/friend_scroll"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_marginTop="10dp"
    android:background="@color/basecolor"
    android:scrollbars="none" >

    <LinearLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/basecolor"
        android:focusable="true"
        android:focusableInTouchMode="true"
        android:orientation="vertical" >
        ......
    </LinearLayout>
</ScrollView>
    仔细看下,发现了什么没有?
        android:focusable="true"
        android:focusableInTouchMode="true"

就是因为这两句,在scrollView中的第一层中,设置这两个属性后,不管ScrollView中的内容与控件长度如何变化,scrollView始终保持在顶端!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值