图库选定的项目背景不持久

时间:2011-05-13 11:41:10

标签: android gallery

我正在使用图库来显示一些图像。我已使用下面的适配器和库选择器来选择库项目。

ImageAdapter:

public class AddImgAdp extends BaseAdapter {

        private int[] galleryImages;

        public AddImgAdp(int[] images) {
            galleryImages = images;


        }

        public int getCount() {
            return galleryImages.length;
        }

        public Object getItem(int position) {
            return position;
        }

        public long getItemId(int position) {
            return position;
        }

        public View getView(final int position, View convertView,
                ViewGroup parent) {

            final ImageView iv = new ImageView(ChooseLinerActivity.this);
            iv.setImageResource(galleryImages[position]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(
                    LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
            iv.setBackgroundDrawable(getResources().getDrawable(
                    R.drawable.galleryselector));


               iv.setAdjustViewBounds(true);

            return iv;

        }
    }

galleryselector:

    <?xml version="1.0" encoding="utf-8"?>

<selector xmlns:android="http://schemas.android.com/apk/res/android">
        <item  android:state_selected="true" 
                        android:drawable="@drawable/large_button_sel2"/>
        <item android:drawable="@android:color/transparent" />
</selector>

我的问题是当我点击或滚动浏览图库时它显示背景,但当我点击图库视图下的另一个视图时,选择消失。

1 个答案:

答案 0 :(得分:0)

因为当您点击图库下的另一个视图时,您的图库没有聚焦。因为您的图库中的视图未被选中。