Gallery setUnselectedAlpha not resuming transparency (alpha) when unselected after being selected

by Chris Cicc » Wed, 08 Oct 2008 23:29:14 GMT


Sponsored Links
 ello All,
I have a gallery with the setUnselectedAlpha option enabled. The
gallery is
set to automatically progress through the gallery items, each time one
is
selected it waits 2 seconds before moving to the next. Before it is
selected, it is transparent. When selected it loses it's transparency,
and
then when it become unselected again it does not return to
transparent!

I have seen at times immediately after closing another activity using
the
back button it will work, but it is not consistent or repeatable.
Perhaps
this is a problem only with the emulator?

Below is the source code: (I have also submitted this as a bug on
Google Code, but it doesn't seem Google actually reviews the bugs in
any reasonable timeframe...)

Gallery declaration:

final HomeGalImgAdapter hgia = new HomeGalImgAdapter(ctx);
final Gallery gal = new Gallery(ctx);
gal.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT,
LayoutParams.WRAP_CONTENT));
gal.setAdapter(hgia);
gal.setSpacing(0);
gal.setUnselectedAlpha(0.3f);
gal.setOnItemSelectedListener(new OnItemSelectedListener() {

public void onItemSelected(AdapterView<?> arg0, View arg1, int arg2,
long
arg3) {
gal.setSelection(arg2);
galType.setText(hgia.getRating(arg2));
galTitle.setText(hgia.getName(arg2));
galAuthor.setText(hgia.getAuthor(arg2));
hgia.pauseBeforeNext(gal);
}

public void onNothingSelected(AdapterView<?> arg0) {

}
});

And the code for the image adapter:

public class HomeGalImgAdapter extends BaseAdapter {
private Context myContext;

private Integer[] myImageIds = {
R.drawable.test128_add_to_folder,
R.drawable.test128_calendar,
R.drawable.test128_chart_pie,
R.drawable.test128_clock,
R.drawable.test128_comments,
R.drawable.test128_info,
R.drawable.test128_mail_receive,
R.drawable.test128_process,
R.drawable.test128_rss,
R.drawable.test128_search,
R.drawable.test128_users
};

/** Simple Constructor saving the 'parent' context. */
public HomeGalImgAdapter(Context c) { this.myContext = c; }

/** Returns the amount of images we have defined. */
public int getCount() { return this.myImageIds.length; }

/* Use the array-Positions as unique IDs */
public Object getItem(int position) { return position; }
public long getItemId(int position) { return position; }

/** Returns a new ImageView to
* be displayed, depending on
* the position passed. */
public View getView(int position, View convertView, ViewGroup
parent) {
ImageView i = new ImageView(this.myContext);

i.setImageResource(this.myImageIds[position]);
/* Image should be scaled as width/height are set. */
i.setScaleType(ImageView.ScaleType.FIT_XY);
/* Set the Width/Height of the ImageView. */
i.setLayoutParams(new Gallery.LayoutParams(96, 96));
return i;
}

private Gallery gal;
private GregorianCalendar time1;
public void pauseBeforeNext(Gallery _gal)
{
gal = _gal;

time1 = new



Other Threads

1. Forcing an activity to reload completely?

You are just lucky that this happens to work, and there are many things you
can do in your activity that will utterly break if you do this.








-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~

2. why cannot i put "hello <b>%s</b>" in strings.xml?

There is public String getString(int id, Object... formatArgs), but this is
built in top of the standard Java String.format(), which can only deal with
raw text (it doesn't know about Android styles), so it can't return a styled
string.






-- 
Dianne Hackborn
Android framework engineer
hack...@android.com

Note: please don't send private questions to me, as I don't have time to
provide private support, and so won't reply to such e-mails.  All such
questions should be posted on public forums, where I and others can see and
answer them.

--~--~---------~--~----~------------~-------~--~----~

3. mediaPlayer.setDataSource(fd) cause IOException: Prepare failed.: status=0x1

4. Android Installation Issue

5. UI Development in Android

6. Forcing an activity to reload completely?

7. TrackBall 'flinging'