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

来源:互联网 发布:c php des加密解密 编辑:程序博客网 时间:2024/05/22 05:20
    在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
原创粉丝点击