android java 代码设置 TextView drawableLeft

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/dhl_1986/article/details/82886320

TextView 能实现一张图配上文字,这样就不用ImageView +TextView,在xml 设置:

  android:drawableLeft="@drawable/xxx"

  但是如果需要动态(代码设置)展示不同的图片和文字,我们该怎么处理呢?

            Drawable leftDrawable = null;
            leftDrawable = mContext.getResources().getDrawable(R.drawable.xxx);
            leftDrawable.setBounds(0, 0, leftDrawable.getMinimumWidth(), 
                leftDrawable.getMinimumHeight());
            tv_video_state.setCompoundDrawables(leftDrawable, null,null , null);

这几行代码必不可少。

猜你喜欢

转载自blog.csdn.net/dhl_1986/article/details/82886320