• Android v4包中的 SwipeRefreshLayout 官方的下拉刷新组件


    SwipeRefreshLayout在v4包下,相应的v4Demo中也有相应的样例。假设没有请下载最新support-v4

    SwipeRefreshLayout 仅仅能有一个直接子View,可能是一个ListView或一个Layout或其它须要刷新的组件。

    setOnRefreshListener 用于监听刷新的动作。SwipeRefreshLayout 下拉。就会有刷新的效果出来,触发该监听。

    假设须要一个刷新的动画,setRefreshing(true), 停: setRefreshing(false)

    假设要禁用刷新动画和手势响应,ssetEnable(false)。  恢复setEnable(true)


    来个v4的样例:

    public class SwipeRefreshLayoutActivity extends Activity implements OnRefreshListener {
        public static final String[] TITLES =
        {
                "Henry IV (1)",
                "Henry V",
                "Henry VIII",
                "Richard II",
                "Richard III",
                "Merchant of Venice",
                "Othello",
                "King Lear",
                "Henry IV (1)",
                "Henry V",
                "Henry VIII",
                "Richard II",
                "Richard III",
                "Merchant of Venice",
                "Othello",
                "King Lear",
                "Henry IV (1)",
                "Henry V",
                "Henry VIII",
                "Richard II",
                "Richard III",
                "Merchant of Venice",
                "Othello",
                "King Lear",
                "Henry IV (1)",
                "Henry V",
                "Henry VIII",
                "Richard II",
                "Richard III",
                "Merchant of Venice",
                "Othello",
                "King Lear"
        };
        // Try a SUPER quick refresh to make sure we don't get extra refreshes
        // while the user's finger is still down.
        private static final boolean SUPER_QUICK_REFRESH = false;
        private View mContent;
        private SwipeRefreshLayout mSwipeRefreshWidget;
        private ListView mList;
        private Handler mHandler = new Handler();
        private final Runnable mRefreshDone = new Runnable() {
    
            @Override
            public void run() {
                mSwipeRefreshWidget.setRefreshing(false);
            }
    
        };
        @Override
        public void onCreate(Bundle bundle) {
            super.onCreate(bundle);
            setContentView(R.layout.swipe_refresh_widget_sample);
            mSwipeRefreshWidget = (SwipeRefreshLayout) findViewById(R.id.swipe_refresh_widget);
            mSwipeRefreshWidget.setColorScheme(R.color.color1, R.color.color2, R.color.color3,
                    R.color.color4);
            mList = (ListView) findViewById(R.id.content);
            ArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>(this,
                    android.R.layout.simple_list_item_1, android.R.id.text1, TITLES);
            mList.setAdapter(arrayAdapter);
            mSwipeRefreshWidget.setOnRefreshListener(this);
            mSwipeRefreshWidget.setProgressViewEndTarget(false, 8);
        }
    
        @Override
        public void onRefresh() {
            refresh();
        }
    
    
        @Override
        public boolean onCreateOptionsMenu(Menu menu) {
            MenuInflater inflater = getMenuInflater();
            inflater.inflate(R.menu.swipe_refresh_menu, menu);
            return true;
        }
    
        /**
         * Click handler for the menu item to force a refresh.
         */
        @Override
        public boolean onOptionsItemSelected(MenuItem item) {
            final int id = item.getItemId();
            switch(id) {
                case R.id.force_refresh:
                    mSwipeRefreshWidget.setRefreshing(true);
                    refresh();
                    return true;
            }
            return false;
        }
    
        private void refresh() {
            mHandler.removeCallbacks(mRefreshDone);
            mHandler.postDelayed(mRefreshDone, 1000);
        }
    }

    swipe_refresh_widget_sample.xml

    <android.support.v4.widget.SwipeRefreshLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/swipe_refresh_widget"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >
    
        <!-- some full screen pullable view that will be the offsetable content -->
    
        <ListView
            android:id="@+id/content"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    </android.support.v4.widget.SwipeRefreshLayout>



  • 相关阅读:
    如何做一个富文本编辑器
    chrome插件开发示例
    使用github Pages和Jekyll搭建一个Blog
    使用JavaScript制作简单的动画
    JQuery模拟七------利用extend包装ajax实现
    JQuery模拟六------jQuery处理事件简化版
    JQuery模拟五------实现属性set&get和CSS set&get
    JQuery模拟四------把用到Sizzle的地方先用CSS3选择器实现
    JQuery模拟三------利用extend函数扩展jQuery自身的方法和浏览器判断
    JQuery模拟二------添加extend函数和简单选择器
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/6746936.html
Copyright © 2020-2023  润新知