动态为TextView控件设置drawableLeft图标,并设置间距

效果图:



重要属性:

textView.setCompoundDrawablePadding(4);//设置图片和text之间的间距 

textView.setPadding(-5, 0, 0, 0);//设置总体的padding

	private TextView addDesc(String[] MemDescs, int i) {
		String MemDesc = MemDescs[i];
		TextView textView = new TextView(this);
		textView.setText(MemDesc);
		//在左側加入图片
		Drawable drawable= getResources().getDrawable(R.drawable.gray_circle);
		drawable.setBounds(0, 0, drawable.getMinimumWidth(), drawable.getMinimumHeight());
		
		textView.setCompoundDrawables(drawable, null, null, null);
		textView.setTextColor(getResources().getColor(R.color.gray_textcolor_shen));
		textView.setCompoundDrawablePadding(4);//设置图片和text之间的间距 
		textView.setPadding(-5, 0, 0, 0);
		return textView;
	}


posted @ 2017-05-23 16:36  mfmdaoyou  阅读(4439)  评论(0编辑  收藏  举报