动态代码添加textView文字图片省略号

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

});

©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容