This is my activity\_main.xml:

```
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:background="#ffffff"
    android:orientation="vertical" >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="40dp"
        android:background="#ffffff" >

        <ImageView
            android:id="@id/imgLogo"
            android:layout_width="100dp"
            android:layout_height="fill_parent"
            android:layout_alignParentLeft="true"
            android:src="@drawable/logo" />

        <TextView
            android:id="@id/txtCurScore"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_centerHorizontal="true"
            android:layout_centerInParent="true"
            android:textColor="#000000"
            android:textSize="28sp"
            android:textStyle="bold" />

        <Button
            android:id="@id/btnTopScore"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_alignParentRight="true"
            android:text="@string/strBtnTopScore"
            android:textColor="#000000"
            android:textStyle="bold" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="0px"
            android:layout_weight="1" >

            <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button3"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button4"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="0px"
            android:layout_weight="1" >

            <Button
                android:id="@+id/button5"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button6"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button7"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button8"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="0px"
            android:layout_weight="1" >

            <Button
                android:id="@+id/button9"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button10"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button11"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button12"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />
        </LinearLayout>

        <LinearLayout
            android:layout_width="wrap_content"
            android:layout_height="0px"
            android:layout_weight="1" >

            <Button
                android:id="@+id/button13"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button14"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button15"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />

            <Button
                android:id="@+id/button16"
                android:layout_width="wrap_content"
                android:layout_height="match_parent"
                android:layout_gravity="center" />
        </LinearLayout>
    </LinearLayout>

</LinearLayout>

```

The above layout has 4x4 buttons with images (images added in code). When user presses the buttons, when 2 consecutive buttons have the same image, I make the two buttons invisible by calling setVisibility(View.GONE).

However I am facing a problem with this approach: Whenever the buttons are set invisible, the layout re-sizes itself. For example, if button[0][0] is set invisible, the remaining 3 buttons in the first row are pushed to the left. So button[0][1] will now occupy the place of button[0][0]. button[0][2] will occupy the place of button[0][1], and button[0][3] will occupy the place of button[0][2].

Please suggest an approach to avoid the buttons move to the left in the layout when any element to the left of it is made invisible in the linear layout.

I tried modifying a bunch of properties, and also searched online. But I couldn't land with any concrete answer to this problem. Please suggest an approach to solve this problem.