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

效果图:

动态为TextView控件设置drawableLeft图标,并设置间距_第1张图片


重要属性:

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


你可能感兴趣的:(Android)