xml布局
<LinearLayout
android:id="@+id/home_frag_list_ll_container"
android:layout_width="match_parent"
android:layout_height="30dp"
android:orientation="horizontal">
</LinearLayout>
//课程详细内容=================01/16========重要的点========
List kcts = courinfoBean.getKcts();
//动态添加TextView for循环也有lambada表达式
kcts.stream().forEach(str->{
TextView textView =new TextView(activity);
//添加文字
textView.setText(str);
//添加一些属性 //图标
Drawable drawable =activity.getDrawable(R.mipmap.tubiao);
//设置图片的位置
drawable.setBounds(0,0,drawable.getIntrinsicWidth(),drawable.getMinimumHeight());
textView.setCompoundDrawables(drawable,null,null,null);
//图标间距 单位是像素
textView.setCompoundDrawablePadding(10);
//垂直居中
textView.setGravity(Gravity.CENTER_VERTICAL);
textView.setTextSize(11);
//省略号
textView.setSingleLine();
textView.setEllipsize(TextUtils.TruncateAt.END);
//文字的margin,通过LayoutParams来设置
LinearLayout.LayoutParams params =new
LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,
ViewGroup.LayoutParams.WRAP_CONTENT);
params.rightMargin=10;
textView.setLayoutParams(params);
//添加到容器
listVH.homeFragListLlContainer.addView(textView);
});