我正在尝试制作一个具有与图像一起滚动的背景的水平图像库。基本上,它看起来像是胶卷上的一系列图片。
有什么想法可以解决这个问题吗?有没有人尝试过这样的事情?
现在,我有一个画廊视图夹在两个带有平铺背景的线性布局之间。这让我得到了我想要的外观,但没有动画。
我终于想通了!希望这可以帮助某人。
public ImageAdapter(Context context) {
galleryContext = context;
imageSizeInPixels = 300; //default value of 300x300 px
TypedArray styleAttr = galleryContext.obtainStyledAttributes(R.styleable.imageGallery);
galleryBackground = styleAttr.getResourceId(R.styleable.imageGallery_android_galleryItemBackground, 0);
styleAttr.recycle();
}
private File[] getFiles() {
File file = new File(GlobalVars.picDir);
File imageList[] = file.listFiles();
return imageList;
}
public int getCount() {
return imageList.length;
}
public Object getItem(int position) {
return position;
}
public long getItemId(int position) {
return position;
}
public View getView(int position, View convertView, ViewGroup parent) {
RelativeLayout container = new RelativeLayout(galleryContext);
ImageView imageView = null;
if (convertView != null) { //we can reuse the view!
imageView = (ImageView) convertView;
} else {
imageView = new ImageView(galleryContext); //boo we have to make a new view
}
//Get a scaled Bitmap so that it doesn't use up all our memory
Bitmap setBitmap = loadScaledBitmap(imageList[position].getAbsolutePath(), imageSizeInPixels);
//set up our ImageView inside the gallery to display our Bitmap...
imageView.setImageBitmap(setBitmap);
imageView.setLayoutParams(new Gallery.LayoutParams(imageSizeInPixels, imageSizeInPixels));
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setBackgroundColor(Color.BLACK);
RelativeLayout borderImg = new RelativeLayout(galleryContext);
borderImg.setPadding(10, 5,10, 5);
borderImg.setBackgroundColor(0xff000000);
borderImg.addView(imageView);
RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(imageSizeInPixels, imageSizeInPixels);
imageParams.addRule(RelativeLayout.CENTER_VERTICAL);
imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);
container.setBackgroundResource(R.drawable.repeat_reel);
container.setLayoutParams(new Gallery.LayoutParams(imageSizeInPixels, imageSizeInPixels+40));
container.addView(borderImg, imageParams);
return container;
}