2021-09-29 流布局跟recyclerView的配合使用

 recyclerViewFavorable.setVisibility(View.VISIBLE);
 //流布局展示
 List<Map<String,Object>> ruleList = new ArrayList<>();
 Map tempMap = null;
for (int i = 0;i<favorableList.length;i++){
    tempMap = new HashMap();
    tempMap.put("name",favorableList[i]);
    ruleList.add(tempMap);
}
 //设置主轴方向为横轴
 FlexboxLayoutManager manager = new FlexboxLayoutManager(this, FlexDirection.ROW);
 //设置item沿主轴方向的位置
 manager.setJustifyContent(JustifyContent.FLEX_START);
 //设置item 沿次轴方向的位置
 manager.setAlignItems(AlignItems.CENTER);

 recyclerViewFavorable.setLayoutManager(manager);
 FavorableRecyclerAdapter favorableRecyclerAdapter =
         new FavorableRecyclerAdapter(R.layout.item_favorable_fullmeet_1,ruleList,false);
 recyclerViewFavorable.setAdapter(favorableRecyclerAdapter);
 favorableAdapter.notifyDataSetChanged();
    <androidx.recyclerview.widget.RecyclerView
        android:id="@+id/recyclerViewFavorable"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/white"
        android:visibility="visible"
        />
/**
 *优惠信息适配器 
 */
public class FavorableRecyclerAdapter extends BaseQuickAdapter<Map<String,Object>, BaseViewHolder> {
    /**
     * 是否是商户列表页面 默认false
     */
    private boolean isMerchantList;

    public FavorableRecyclerAdapter(int layoutResId, @Nullable List<Map<String,Object>>  data,boolean isMerchantList) {
        super(layoutResId, data);
        this.isMerchantList = isMerchantList;
    }

    @Override
    protected void convert(BaseViewHolder baseViewHolder, Map<String,Object> objectMap) {
        TextView tvFavorable = baseViewHolder.getView(R.id.tvFavorable);
        if(isMerchantList){
            tvFavorable.setTextSize(11);
            //商户列表的本行商户优惠信息展示
//            if (myList != null && myList.size() > 0) {
//                Map<String,Object> map = myList.get(position);
               tvFavorable.setText(JsonUtils.getString(objectMap.get("meetMoney"))+"减"+JsonUtils.getString(objectMap.get("reductionMoney")));
//            }

        }else {
//            if (list != null && list.length > 0) {
                //详情大小12
                tvFavorable.setTextSize(12);
                tvFavorable.setBackgroundResource(R.drawable.shape_stroke_red_favorable_detail);//替换边框

                String favorable = JsonUtils.getString(JsonUtils.getString(objectMap.get("name")));
                tvFavorable.setText(favorable.replace("-", "减"));
//            }
        }
    }

}

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值