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);

  • 相关阅读:
    4-1 zookeeper常用命令行操作
    3 zookeeper 基本数据模型
    2 ZooKeep安装
    1 zookeeper的特性
    js数据类型
    javascript中的严格模式
    2 Vue中组件开发
    1 Vue的基础语法
    责任链设计模式
    四中网络专线接入方式
  • 原文地址:https://www.cnblogs.com/yushilong/p/3891726.html
Copyright © 2011-2022 走看看