1. 程式人生 > >動態設定view的padding和margin值,TextView drawLeft drawRight

動態設定view的padding和margin值,TextView drawLeft drawRight

1、動態設定padding,拿ImageView為例

 ImageView imageView = new ImageView(Context context);  
 imageView.setPadding(left,top,right,bottom);

2、動態設定margin,拿LinearLayout裡邊放ImageVIew為例
LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(20, 20);  
  params.setMargins(20, 0, 20, 0);  
  imageView.setLayoutParams(params);

3、動態設定TextView drawLeft drawRight
Drawable rightDrawable = getResources().getDrawable(R.drawable.icon_new);  
rightDrawable.setBounds(0, 0, rightDrawable.getMinimumWidth(), rightDrawable.getMinimumHeight());  
textview.setCompoundDrawables(null, null, rightDrawable, null);