@Override
public void bindHolder(RecyclerView.ViewHolder holder, int position, final Product data) {
if(holder instanceof PHolder){
WindowManager windowManager = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
Display display = windowManager.getDefaultDisplay();
DisplayMetrics displayMetrics = new DisplayMetrics();
display.getMetrics(displayMetrics);
// 高度与宽度相同
int width = (int) (displayMetrics.widthPixels - context.getResources().getDimension(R.dimen.fenLeiWidth) - context.getResources().getDimension(R.dimen.smallMargin)*2
- context.getResources().getDimension(R.dimen.smallerMargin)*2) / 2;
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.height = width;
((PHolder) holder).icon.setLayoutParams(layoutParams);
MyUtil.loadPic(context,((PHolder) holder).icon,data.getImgs(),false,false);
((PHolder) holder).title.setText(data.getName());
// 跳转到商品详情页
holder.itemView.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
Intent intent = new Intent(context, ProductDetailActivity.class);
intent.putExtra("id",data.getId());
context.startActivity(intent);
}
});
}
}
屏幕适配 图片的高度和宽度一样
最新推荐文章于 2024-05-02 17:26:27 发布