zoukankan      html  css  js  c++  java
  • 开源控件PullToRefreshGridView的使用(一)

    该开源项目地址:https://github.com/chrisbanes/Android-PullToRefresh

    1.单排单列和单排双列

    先看效果图:

             

    核心代码:

    a、定义一个枚举类

        public enum Type {
            LINE_ONE, LINE_TWO//LINE_ONE单排单列   LINE_TWO单排双列
        }
    

    提供枚举类type的set和get方法。

    b、新建一个adapter继承baseadapter,重写getView方法

    if (Type.LINE_ONE == type)
       {
          convertView = LayoutInflater.from(mContext.getActivity()).inflate(R.layout.b5m_search_result_item, null);
         }
    else if (Type.LINE_TWO == type)
         {
             convertView = LayoutInflater.from(mContext.getActivity()).inflate(R.layout.b5m_search_result_item_grid, null);
          }

    c、动态改变布局格式

    mGridView.setAdapter(mAdapter);

    mGridView.setNumColumns(Type.LINE_ONE == type?1:2);

    在PullToRefreshGridView中就是

    mPullToRefreshGridView.getRefreshableView.setNumColumns(Type.LINE_ONE == type?1:2);

    注意事项:

    防止GridView缓存view对布局的影响,更换布局样式先应先清掉缓存view

    mPullToRefreshGridView.setAdapter(null);

    然后再设置adapter

    mPullToRefreshGridView.setAdapter(mAdapter);

    int numColums = mPullToRefreshGridView.getRefreshableView.getNumColums();

    mAdapter.setType(numColums==1?Type.LINE_TWO:Type.LINE_ONE);

  • 相关阅读:
    Vue Bug
    Vue.js(一)
    Node.js简介
    对请求链接的URLEncode处理
    淘宝开放平台
    Java基础(一)
    计算机基础知识
    Unity中对象池的使用
    希尔排序算法
    插入排序算法
  • 原文地址:https://www.cnblogs.com/yushilong/p/3891726.html
Copyright © 2011-2022 走看看