Android动态添加TextView

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);

 }
发布了40 篇原创文章 · 获赞 37 · 访问量 9万+

猜你喜欢

转载自blog.csdn.net/sanyang730/article/details/51395951