Search code examples
androidgalleryalpha-transparency

Gallery android:unselectedAlpha


I have a Gallery that works perfectly, except only the first element is ever displayed at full alpha.

I have the Gallery's style set to style="android:galleryItemBackground", and android:unselectedAlpha="0.75" is also set. This works, in that the first element is shown without transparency, and the second appears to be faded some.

The issue is, when I scroll the gallery, the items never become unfaded. They're all alpha=0.75, even when they're the selected item. The items do have an OnItemClickListener set, and this listener works fine.

I am unable to find an answer to how to get this working, so I thought I'd ask here.

[ edit ] I've also tried setting an OnItemSelectedListener and manually setting the View's alpha to 1 if the position = selectedPosition in the getView of the Adapter. No luck.


Solution

  • Add background on every of its child view

    This is one example code

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View view = null;
    
        if (convertView == null) {
            view = mInflater.inflate(R.layout.some_layout, parent, false);
        } else {
            view = convertView;
        }
    
        // have to set background to make selection alpha works
        view.setBackgroundColor(0x22ffffff);
    
    
        return view;
    }
    

    Hope it helps