1. TextView加横线的属性
例如:加下划线和价钱上加横线
底部加横线是
textview.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG );
textview.getPaint().setFlags(Paint. UNDERLINE_TEXT_FLAG
|Paint.ANTI_ALIAS_FLAG);加上后面的属性字体更清晰一些
中间加横线是:
textview.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG );这个属性的字体有点模糊不清
textview.getPaint().setFlags(Paint. STRIKE_THRU_TEXT_FLAG |Paint.ANTI_ALIAS_FLAG);加上这个属性,字体更清晰一些
参考文章:http://blog.csdn.net/aaawqqq/article/details/27861017
==================================================
2. TextView在代码中动态添加图片
Drawable shareMip= getResources().getDrawable(R.mipmap.icon_support);
shareMip.setBounds(0, 0, shareMip.getMinimumWidth(), shareMip.getMinimumHeight());
textviewTitle.setCompoundDrawables(shareMip, null, null, null);
同样,参考另一种函数
public void setCompoundDrawablesWithIntrinsicBounds(Drawable left,Drawable top,Drawable right,Drawable bottom)
Sets the Drawables (if any) to appear to the left of, above, to the right of, and below the text. Use null if you do not want a Drawable there. The Drawables' bounds will be set to their intrinsic bounds.
例如:
TextView mTextView = (TextView) linearLayout.findViewById(R.id.tv_select_item);
mTextView.setCompoundDrawables(drawable,null,null,null);//设置TextView的drawableleft
mTextView.setCompoundDrawablePadding(10);//设置图片和text之间的间距
mTextView.setText(mSelfSelect[i]);
// 添加到屏幕布局
LayoutParams layoutParams = new LinearLayout.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT);
mLayout.addView(linearLayout, layoutParams);