画廊选择的项目backgound坚持不 [英] Gallery selected item backgound not persisting

查看:86
本文介绍了画廊选择的项目backgound坚持不的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用的画廊显示一些图像。我用下面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.

这篇关于画廊选择的项目backgound坚持不的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆