Centering The Matrix Of Imageviews To The Center Of The Screen Dynamically
This is my Layout File: RelativeLayout xmlns:android='http://schemas.android.com/apk/res/android' xmlns:tools='http://schemas.android.com/tools' android:id='@+id/image
Solution 1:
As I said you could wrap the image matrix in another RelativeLayout
and center that in in the initial RelativeLayout
:
RelativeLayoutre= (RelativeLayout)findViewById(R.id.imageLayout);
RelativeLayoutcontent=newRelativeLayout(this);
RelativeLayout.LayoutParamsclp=newRelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
clp.addRule(RelativeLayout.CENTER_IN_PARENT);
content.setLayoutParams(clp);
for (inti=0; i < rows; i++) {
for (intj=0; j < cols; j++) {
// ...the current loop...
img.setLayoutParams(rlp);
content.addView(img);
}
}
re.addView(content);
Also remove the android:gravity
and the android:layout_gravity
properties from the xml RelativeLayout
.
Post a Comment for "Centering The Matrix Of Imageviews To The Center Of The Screen Dynamically"