我在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;
}
}
数组中有3张图片。
我的下面的代码随机显示图像,而我希望它们是唯一的,并能够连续滚动。
我的适配器代码是。
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) {
}
});
}
我的主要活动代码是
purchaseList.filter { (element) -> Bool in
return (element["purchaseCategory"] as? [String])?.contains("olive") ?? false
}
答案 0 :(得分: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;
}