Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Hope this is helpful. I manage to "simulate" the shrink/grow solution with the <code>Gallery</code> widget. Since they removed the <code>getScale()</code>, things get a little bit complicated. I think that this it's not the best solution at all, but at least I can live with it.</p> <p>What I have found is that <code>Gallery</code> manages the focus EXTREMELY BAD. So, the first approach was to add a focus change listener on the <code>ImageView</code> displayed, but no luck there. Focus is a MESS there... in terms that, the selected image it's not the currently focused view. I have sent a mail to android-developers mailing list about some error on API doc (regarding the <code>focusSearch()</code>method and some focus contants).</p> <p>Here's my solution to this problem:</p> <p>Build an animation resource to 'grow' the image:</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.10" android:fromYScale="1.0" android:toYScale="1.10" android:duration="300" android:pivotX="50%" android:pivotY="50%" android:interpolator="@android:anim/accelerate_decelerate_interpolator" android:fillAfter="false"/&gt; </code></pre> <p>If you don't get what that means then you should proceed to read <a href="http://developer.android.com/intl/fr/guide/topics/resources/animation-resource.html" rel="noreferrer">this</a></p> <p>That will be our 'grow' effect, and you will need to save it in: <code>res/anim/grow.xml</code> or whatever name it suites you (but always in res/anim dir).</p> <p>You can follow the resource guide from <a href="http://developer.android.com/intl/fr/resources/tutorials/views/hello-gallery.html" rel="noreferrer">here</a> to create a <code>Gallery</code> view. The <code>ImageAdapter</code> builds an <code>ImageView</code> every time that the <code>Gallery</code> object calls <code>getView()</code>. One workaround you could implement is adding a line to the <code>getView()</code> method that identifies a <code>View</code> with a <code>position</code>, this way:</p> <pre><code>... i.setId(position); ... </code></pre> <p>With that line added to the <code>getView()</code> method of the <code>ImageAdpater</code> object, you can then unequivocally identify that view within a listener, for instance:</p> <pre><code>g.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() { public void onItemSelected (AdapterView&lt;?&gt; parent, View v, int position, long id) { Animation grow = AnimationUtils.loadAnimation(YourActivity.this, R.anim.grow); View sideView = parent.findViewById(position - 1); if (sideView != null) ((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(150, 100)); sideView = parent.findViewById(position + 1); if (sideView != null) ((ImageView)sideView).setLayoutParams(new Gallery.LayoutParams(150, 100)); v.startAnimation(grow); v.setLayoutParams(new Gallery.LayoutParams(170, 150)); } public void onNothingSelected (AdapterView&lt;?&gt; parent) { System.out.println("NOTHING SELECTED"); } }); </code></pre> <p>NOTE: You may notice that all the values from animation and from layout parameters has been choosen by me at hand. This is because i'm not going to clean code for you. And, this is just a workaround the BAD focus issue with this widget or the android view system. If focus were OK, then, all you need to do is set a focus change listener that makes the gros/shrink when it got focus/unfocused.</p> <p>I hope this may help you to find a way around for your problem,</p> <p>Regards,</p> <p>New EDIT: This is the listener I have set, I also added the line <code>i.clearAnimation()</code> in the <code>getView()</code> method:</p> <pre><code>private class SelectListener implements AdapterView.OnItemSelectedListener { private Animation grow; private int last; public SelectListener() { grow = AnimationUtils.loadAnimation(RouteGallery.this, R.anim.grow); last = 0; } public void onItemSelected (AdapterView&lt;?&gt; parent, View v, int position, long id) { View sideView = parent.findViewById(last); if (sideView != null &amp;&amp; last != position) sideView.clearAnimation(); v.startAnimation(grow); last = position; } public void onNothingSelected (AdapterView&lt;?&gt; parent) { } } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload