3 Star 44 Fork 10

Ryan Zhu / OhosExtension

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
EasyGridProvider.md 2.01 KB
一键复制 编辑 原始数据 按行查看 历史
朱帆 提交于 2021-07-22 09:51 . 新增部分工具类与控件

EasyGridProvider

实现网格布局的ItemProvider

自定义Provider继承EasyGridProvider

public class MyBaseQuickAdapter extends EasyGridProvider<UserViewInfo> {

    public MyBaseQuickAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    protected void bind(ViewHolder holder, UserViewInfo item, int position) {
        Image thumbView = holder.getView(ResourceTable.Id_iv);
        iv.setVisibility(Component.VISIBLE);
        
    }

    @Override
    protected void bindPlaceholder(ViewHolder holder, int position) {
        Image iv = holder.getView(ResourceTable.Id_iv);
        iv.setVisibility(Component.HIDE);
    }

    @Override
    protected int getLayoutId() {
        return ResourceTable.Layout_item_image_grid;
    }
}

布局文件

<?xml version="1.0" encoding="utf-8"?>
<DependentLayout
    xmlns:ohos="http://schemas.huawei.com/res/ohos"
    ohos:height="match_parent"
    ohos:width="match_parent"
    >

    <Image
        ohos:id="$+id:iv"
        ohos:height="match_parent"
        ohos:width="match_parent"
        />
</DependentLayout>

ListContainer设置适配器

  ListContainer listContainer = (ListContainer) findComponentById(ResourceTable.Id_listView);
  MyBaseQuickAdapter myBaseQuickAdapter = new MyBaseQuickAdapter(this);
  //设置数据
  myBaseQuickAdapter.setData();
  //设置网格数
  myBaseQuickAdapter.setNumColumns(2);
  //设置网格间隙
  myBaseQuickAdapter.setGridSpacing(0);
  //设置点击事件
  listContainer.setItemProvider(myBaseQuickAdapter);
  myBaseQuickAdapter.setOnItemClickListener(new EasyGridProvider.OnItemClickListener() {
      @Override
      public void onItemClick(Component component, int position) {

      }
  });

横竖屏切换

 protected void onOrientationChanged(AbilityInfo.DisplayOrientation displayOrientation) {
    super.onOrientationChanged(displayOrientation);
    myBaseQuickAdapter.updateDisplayWidth(displayOrientation);
    myBaseQuickAdapter.notifyDataChanged();
}
Java
1
https://gitee.com/thoseyears/ohos-extension.git
git@gitee.com:thoseyears/ohos-extension.git
thoseyears
ohos-extension
OhosExtension
master

搜索帮助