Android动态添加TextView
16lz
2021-01-23
LinearLayout.LayoutParams params=new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.WRAP_CONTENT);
for (int i = 0; i < items.size(); i++) { TextView mTv= new TextView(mContext); mTv.setLayoutParams(params); mTv.setLineSpacing(1.2f, 1.2f);//设置行间距 mTv.setTextColor(mContext.getResources().getColor(R.color.text_light_black)); mTv.setTextSize(TypedValue.COMPLEX_UNIT_SP,15); mTv.setText(i+1+"."+items.get(i).getSubName()); System.out.println("mTv="+mTv.getText()+items.get(i).getSubName()); holder.ll_content.addView(mTv,i,params); }