设置字体大小:
setTextSize(TypedValue.COMPLEX_UNIT_PX,22); //22像素
setTextSize(TypedValue.COMPLEX_UNIT_SP,22); //22SP
setTextSize(TypedValue.COMPLEX_UNIT_DIP,22);//22DIP
设置layout_weight:
setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT, 1.0f));
最后的1.0f即是,需要是浮点型的才行
LayoutParams中使用dip作为单位:
final int iv_width = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 22, getResources().getDisplayMetrics()); final int iv_height = (int)TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP, 22, getResources().getDisplayMetrics()); ImageView iv = new ImageView(this); iv.setLayoutParams(new LinearLayout.LayoutParams(iv_width, iv_height)); iv.setImageResource(R.drawable.check); iv.setTag(phone_number); line_pn.addView(iv);
判断ImageView是否是visible的:
if (myImageView.getVisibility() == View.VISIBLE) { // Its visible } else { // Either gone or invisible }