本文主要是介绍android的recyView设置item先是不同的高度,类似瀑布流,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
解决方案是:在adapter里获取了item的高度做了一个数值范围内(设置高度的下限和高度的上限,这里设置的高度是最低值加上一个范围内的随机数的值),这样就ok了,这里的适配器集成了万能的适配器BRVAH
public class BRVAHImgAdapter extends BaseQuickAdapter<ImgEntryResponse, BaseViewHolder> {private final static String IMG_URL = CommonServerUrl.IMG_SERVER_URL;//最新地址List<ImgEntryResponse> mBRVAHImgObjList;//构造public BRVAHImgAdapter(int layoutResId, List<ImgEntryResponse> data) {super(layoutResId, data);}@Overrideprotected void convert(@NonNull BaseViewHolder helper, ImgEntryResponse item) {//helper.setText(R.id.id_text, "第" + helper.getAdapterPosition() + "个数据");ImageView img_view = helper.getView(R.id.iv_indexImg_brvah);String url = IMG_URL + item.getPT();Glide.with(mContext).load(url).placeholder(R.drawable.prestrain_icon)//加载占位图/图片未加载,提前展示给用户
// .skipMemoryCache(true)
// .diskCacheStrategy(DiskCacheStrategy.NONE).fitCenter().listener(new RequestListener<Drawable>() {@Overridepublic boolean onLoadFailed(@Nullable GlideException e, Object model, Target<Drawable> target, boolean isFirstResource) {Log.d("Wain", "BRVAH成功le加载失败 errorMsg:" + (e != null ? e.getMessage() : "null"));return false;}@Overridepublic boolean onResourceReady(Drawable resource, Object model, Target<Drawable> target, DataSource dataSource, boolean isFirstResource) {Log.d("BRVAH成功le", "BRVAH成功le Drawable Name:" + resource.getClass().getCanonicalName());return false;}}).into(img_view);// helper.setText(R.id.tv_imgName, item.getD());int position = helper.getLayoutPosition();Log.d("当前条目的位置++", position + "");//获取item宽度,计算图片等比例缩放后的高度,为imageView设置参数ViewGroup.LayoutParams params = img_view.getLayoutParams();WindowManager wm= (WindowManager) mContext.getSystemService(Context.WINDOW_SERVICE);int width = wm.getDefaultDisplay().getWidth();//设置图片的相对于屏幕的宽高比params.width = width / 2;params.height = (int) (260 + Math.random() * 330);//设置随机高度img_view.setLayoutParams(params);}}
这篇关于android的recyView设置item先是不同的高度,类似瀑布流的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!