protected void showPraises(final List<PraiseInfo> praises, final RelativeLayout container) { container.removeAllViews(); container.setVisibility(View.VISIBLE); int size = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 30, getResources().getDisplayMetrics()); int margin = (int) TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 2, getResources().getDisplayMetrics()); for(int i = 0 ;i<praises.size();i++){ final PraiseInfo info = praises.get(i); ImageView iv = new ImageView(this); iv.setId(i+1); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(size, size); if(i%6==0){ params.addRule(RelativeLayout.BELOW, i-5); }else{ params.addRule(RelativeLayout.RIGHT_OF, i); params.addRule(RelativeLayout.BELOW, i-5); } params.setMargins(margin, margin, margin, margin); iv.setBackground(getResources().getDrawable(R.drawable.bg_border)); iv.setLayoutParams(params); ImageUtils.setHeadImage(info.getPhoto(), iv); iv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { AppManager.getPersonalDates(DynamicdetailsActivity2.this, info.getUsername()); } }); if(!isFirstShow||i<3){ if(!isFirstShow&&showPageNumber>0){ if(i<showPageNumber*10){ container.addView(iv); } }else{ container.addView(iv); } }else{ break; } } TextView tv = new TextView(this); ImageView ivback = new ImageView(this); if((!isFirstShow&&praises.size()<10*showPageNumber) ||praises.size()<3){ tv.setVisibility(View.GONE); Log.i("TAG", "进入了"); if(!isFirstShow&&praises.size()<10*showPageNumber){ RelativeLayout.LayoutParams params1 = new RelativeLayout .LayoutParams(size, size); params1.addRule(RelativeLayout.ALIGN_PARENT_BOTTOM); if(praises.size()%6!=0){ params1.addRule(RelativeLayout.RIGHT_OF, praises.size()); }else{ params1.addRule(RelativeLayout.BELOW, praises.size()-5); } params1.setMargins(margin, margin, margin, margin); ivback.setLayoutParams(params1); ImageUtils.setImgFromDrawable(R.drawable.close_avtar, ivback, true); ivback.setScaleType(ScaleType.MATRIX); ivback.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { isFirstShow=true; isCache = true; showPageNumber=0; showPraises(praises, container); } }); container.addView(ivback); } }else{ ivback.setVisibility(View.GONE); Log.i("TAG", "显示了"); RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(size, size); tv.setText("......"); tv.setGravity(Gravity.BOTTOM); tv.setTextColor(Color.parseColor("#ff6600")); params.addRule(RelativeLayout.CENTER_VERTICAL); if(isFirstShow){ params.addRule(RelativeLayout.RIGHT_OF, 3); }else{ params.addRule(RelativeLayout.RIGHT_OF,10*showPageNumber); params.addRule(RelativeLayout.BELOW,10*showPageNumber-5); } params.setMargins(margin,margin,margin,margin); tv.setLayoutParams(params); tv.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { if(isFirstShow){ isFirstShow=false; showPageNumber +=1 ; showPraises(praises, container); }else{ showPageNumber +=1 ; if(isCache){ showPraises(praises, container); }else{ initPraiseList(); } } } }); container.addView(tv); } }
关于自定义layout
最新推荐文章于 2021-08-05 09:48:07 发布