Android Gallery Scale Center Image & Spacing Issue
<p>I have an <code>Activity</code> containing a <code>Gallery</code> view.  I've defined an <code>onItemSelectedListener</code> on the <code>Gallery</code>, so that whenever an item is selected I apply a scale animation to the currently selected view.  The listener, and scaling works pretty much as expected, except for one issue. </p>

<p>When I defined the Gallery, I set the <code>spacing</code> attribute, however, after the view is scaled, the spacing is not being set properly.  See the image below as an example of the issue.</p>

<p>Any thoughts on how I can maintain the proper spacing?   </p>

<p><img src="http://i.stack.imgur.com/0h1tU.png" alt="enter image description here"></p>

<p>Below are snippets of the code:</p>

<p><strong>main.xml</strong></p>

<p>
</p>

<pre><code>&lt;Gallery
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/featured_gallery"
    android:layout_width="1355px"
    android:layout_height="490px"
    android:layout_gravity="center"
    android:spacing="5px"
    android:layout_marginTop="70dp"
     /&gt;    
</code></pre>

<p></p>

<p><strong>feature_selected.xml</strong></p>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;scale xmlns:android="http://schemas.android.com/apk/res/android"
   android:fromXScale="1.0"
   android:toXScale="1.075"
   android:fromYScale="1.0"
   android:toYScale="1.075"
   android:duration="100"
   android:pivotX="50%"
   android:pivotY="50%"

   android:interpolator="@android:anim/accelerate_decelerate_interpolator"
   android:fillAfter="true"&gt; 
&lt;/scale&gt;
</code></pre>

<p><strong>onItemSelectListener</strong></p>

<pre><code>private class FeaturedSelectListener implements AdapterView.OnItemSelectedListener {

    private Animation grow = null;
    private View lastView = null;

    public FeaturedSelectListener(Context c) {
        grow = AnimationUtils.loadAnimation(c, R.anim.featured_selected);
    }

    @Override
    public void onItemSelected(AdapterView&lt;?&gt; parent, View view, int position, long id) {
        // Shrink the view that was zoomed
        try {
            if (null != lastView)
                lastView.clearAnimation();
        } catch (Exception clear) {
        }

        // Zoom the new selected view
        try {
            view.startAnimation(grow);
        } catch (Exception animate) {
        }

        // Set the last view so we can clear the animation
        lastView = view;

    }

    @Override
    public void onNothingSelected(AdapterView&lt;?&gt; arg0) {
        // TODO Auto-generated method stub

    }

}
</code></pre>
