I want to set the gravity of an array of Imageviews,ImageIcons[i] to the center with the following code,
ImageIcons[i] = new ImageView(this); ImageIcons[i].setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT)); layout.addView(ImageIcons[i]);
And I am stuck up while setting the gravity.I request the SO people to guide me on this.
Thanks
Try this
LinearLayout.LayoutParams layoutParams=new LinearLayout.LayoutParams(width, height); layoutParams.gravity=Gravity.CENTER; ImageIcons[i].setLayoutParams(layoutParams);
get the layout parameters from view, modify it and set it again.
image.setBackgroundResource(R.drawable.mobile); LayoutParams params = (LayoutParams) image.getLayoutParams(); params.gravity = Gravity.CENTER; image.setLayoutParams(params);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With