I’m using dynamic layout I want to set width and height of a ImageView. The code is below. How can I set the height and width of an ImageView in a given layout? Any help is highly appreciated.
RelativeLayout layout = new RelativeLayout(mContext);
TextView text1 = new TextView(mContext);
text1.setText(Constants.vctrCategory.elementAt(counter).toString());
LayoutParams params1 = new LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
text1.setLayoutParams(params1);
text1.setTextSize(20);
layout.addView(text1);
ImageView image = new ImageView(mContext);
image.setImageBitmap(bitmap);
layout.addView(image);
counter++;
return layout;
Rather can calling calling
addView()with just theImageView, you could use the version that also takes two integers for the width and height:addView(View child, int width, int height)
Alternatively, you can set the width and/or height directly on the view’s
LayoutParams, i.e. after thelayout.addView(image)call in your own snippet:Basically it’s similar to what you’re already doing for the
TextView.