zoukankan      html  css  js  c++  java
  • 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>



  • 相关阅读:
    一口一口吃掉Hibernate(八)——Hibernate中inverse的用法
    一口一口吃掉Hibernate(七)——继承映射
    一口一口吃掉Hibernate(六)——多对多关联映射
    一口一口吃掉Hibernate(五)——一对多单向关联映射
    一口一口吃掉Hibernate(四)——多对一单向关联映射
    Hibernate给表和字段设置前后缀及分隔符
    Hibernate中Session之get和load方法的真正区别
    oracle中关于日期的获取
    java中去掉字符串空格
    实现html与html 页面之间传递参数以及接收参数
  • 原文地址:https://www.cnblogs.com/wzzkaifa/p/6746936.html
Copyright © 2011-2022 走看看