0

这三张图是随机显示的,我想按顺序显示

位置 0 和 2 有相同的图片我希望它们是独一无二的

我在images[]数组中有 3 个图像。我的以下代码随机显示图像,而我希望它们是唯一的并且能够连续滚动。我的适配器代码是。

public class FancyCoverFlowSampleAdapter extends FancyCoverFlowAdapter {

    // =============================================================================
    // Private members
    // =============================================================================

    private int[] images = {R.drawable.promtion_hover, R.drawable.hot_item_hover, R.drawable.siore_location_hover};

    // =============================================================================
    // Supertype overrides
    // =============================================================================

    @Override
    public int getCount() {
        return Integer.MAX_VALUE;
    }

    @Override
    public Integer getItem(int i) {
        return images[i];
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    int pos = 0;

    @Override
    public View getCoverFlowItem(final int i, View reuseableView, ViewGroup viewGroup) {
        ImageView imageView = null;
        Log.e("i=",""+i);
        Log.e("i=",""+i);

        if (reuseableView != null) {
            imageView = (ImageView) reuseableView;
        } else {
            imageView = new ImageView(viewGroup.getContext());
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imageView.setLayoutParams(new FancyCoverFlow.LayoutParams(350, 650));

        }
   /*     if (pos >= images.length -1)
            pos = 0;
        else
            ++pos;*/
        imageView.setImageResource(/*images[pos]*/this.getItem(pos));

        return imageView;
    }
}

我的主要活动代码是

public class MainActivity  extends Activity {
    private FancyCoverFlow fancyCoverFlow;


    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        this.fancyCoverFlow = (FancyCoverFlow) this.findViewById(R.id.fancyCoverFlow);

        this.fancyCoverFlow.setAdapter(new FancyCoverFlowSampleAdapter());
        this.fancyCoverFlow.setUnselectedAlpha(1.0f);
        this.fancyCoverFlow.setUnselectedSaturation(0.0f);
        this.fancyCoverFlow.setUnselectedScale(0.5f);
        this.fancyCoverFlow.setSpacing(-56);
        this.fancyCoverFlow.setMaxRotation(0);
        this.fancyCoverFlow.setScaleDownGravity(0.2f);
        this.fancyCoverFlow.setActionDistance(FancyCoverFlow.ACTION_DISTANCE_AUTO);
        this.fancyCoverFlow.setOnItemSelectedListener(new AdapterView.OnItemSelectedListener() {
            @Override
            public void onItemSelected(AdapterView<?> parent, View view, int position, long id) {
              //  Toast.makeText(getApplication(),"Position="+position,Toast.LENGTH_LONG).show();
            }

            @Override
            public void onNothingSelected(AdapterView<?> parent) {

            }
        });

    }
4

1 回答 1

0

尝试在您的代码中更正/替换以下代码:

 @Override
 public int getCount() {
   return images.length;
 }

@Override
public View getCoverFlowItem(final int i, View reuseableView, ViewGroup viewGroup) {
    ImageView imageView = null;

    if (reuseableView != null) {
        imageView = (ImageView) reuseableView;
    } else {
        imageView = new ImageView(viewGroup.getContext());
        imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
        imageView.setLayoutParams(new FancyCoverFlow.LayoutParams(350, 650));
    }

    imageView.setImageResource(this.getItem(i));

    return imageView;
}
于 2015-09-29T12:22:08.287 回答