效果图:

动态为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;
	}


相关文章:

  • 2021-06-20
  • 2022-12-23
  • 2021-06-10
  • 2022-12-23
  • 2022-12-23
  • 2021-07-20
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-01-17
  • 2021-06-18
相关资源
相似解决方案