android 如何动态设置View的margin和padding

原文地址:http://blog.csdn.net/a107494639/article/details/7341077


1.动态设置padding,拿ImageView为例:

[java] view plain copy
  1. ImageView imageView = new ImageView(this);  
  2. imageView.setPadding(5,5,5,5)  

2.动态设置margin

拿LinearLayout里边放ImageVIew例:

[java] view plain copy
  1. LinearLayout layout = (LinearLayout) convertView.findViewById(R.id.linearlayout);  
  2. ImageView imageView = new ImageView(this);  
  3. LinearLayout.LayoutParams params = new LinearLayout.LayoutParams(100100);  
  4. params.setMargins(5555);  
  5. layout.addView(imageView); 

你可能感兴趣的:(android 如何动态设置View的margin和padding)