画廊选择的项目backgound坚持不画廊、项目、backgound

2023-09-06 19:10:39 作者:Floating(浮生)

我使用的画廊显示一些图像。我用下面adpater和画廊选择的画廊选择的项目。

I'm using gallery to display some images. I have used below adpater and gallery selector for gallery item selection.

ImageAdapter:

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:

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>

我的问题是,当我点击或通过画廊滚动它显示的背景,但是当我点击另一种观点认为这是在画廊视图,然后选择消失。

My problem is when I click or scroll through gallery it displays background, but when I click on another view which is under gallery view then the selection disappears.

推荐答案

由于当您单击另一种观点认为这是画廊下,您的画廊是unfocused.of事业,观点您的画廊是不选。

Because when you click another view which is under the gallery, your gallery was unfocused.of cause, views in your gallery were unselected.