SwipeRefreshLayout简单说明

SwipeRefreshLayout是谷歌官方的下拉刷新控件,代码在V4包中。

使用SwipeRefreshLayout有几个要注意的:

  1. SwipeRefreshLayout和ScrollView一样只能有一个字控件。

  2. setOnRefreshListener设置监听刷新。

  3. setProgressBackgroundColor设置刷新时圆形进度条的背景色

  4. setColorSchemeResources设置刷新时进度条颜色

  5. setRefreshing设置刷新状态

  6. setSize设置大小,现在只有SwipeRefreshLayout.DEFAULT,SwipeRefreshLayout.LARGE

如果在SwipeRefreshLayout的子控件中嵌套了其他可滚动控件例如

 <android.support.v4.widget.SwipeRefreshLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
                <ScrollView
                    android:layout_width="match_parent"
                    android:layout_height="0dip"
                    android:layout_weight="1"
                    android:id="@id/svCar"
                    android:fadingEdge="none" >
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
                </ScrollView>
                    <TextView
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"/>
        </LinearLayout>        
</android.support.v4.widget.SwipeRefreshLayout>

当ScrollView滚动到下方后,向下拉ScrollView不会滚动而会出现下拉刷新动作,这时需要将ScrollView设置onTouch事件

    OnTouchListener onTouchListener=new OnTouchListener() {
        
        @Override
        public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
            case MotionEvent.ACTION_DOWN:
            case MotionEvent.ACTION_MOVE:
            case MotionEvent.ACTION_UP:
                if (svCar.getScrollY() > 0) {
                    srlCar.setEnabled(false);
                } else {
                    srlCar.setEnabled(true);
                }
                break;
            }
            return false;
        }
    };

转载于:https://my.oschina.net/u/2406628/blog/496249

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值