如何用代码创建ImageView ,并设置图片
//定义ImageView(两种方式)ImageView imageView = new ImageView(this); //orImageView imageView = (ImageView)this.findViewById(R.id.xxxx); //or//通过ImageView控件显示图片(三种方式)imageView.setImageBitmap(Bitmap bm); // orimageView.setImageDrawable(Drawable drawable); //orimageView.setImageResource(int resId); //or
如何通过代码设置TextView的Margin参数?
首先定义个LayoutParams,然后在设置margin,在把这个LayoutParams设置给控件,如下:
LinearLayout.LayoutParams layoutParams = new LinearLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT, ViewGroup.LayoutParams.WRAP_CONTENT);
layoutParams.setMargins(10,10,10,10);//4个参数按顺序分别是左上右下
mView.setLayoutParams(layoutParams);