安卓:滚动背景画廊 [英] Android: Scrolling Background in Gallery
本文介绍了安卓:滚动背景画廊的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我试图让有背景的水平图库与图像一起滚动。基本上,它的意思看起来像一个胶卷的系列照片。
I'm trying to make a horizontal image gallery that has a background that scrolls along with the images. Basically, it's meant to look like a series of pictures on a film roll.
是否有一个如何去任何想法?有没有人尝试过这样的事?
Are there any ideas of how to go about this? Has anyone ever tried anything like this?
现在,我夹在两个LinearLayouts与瓷砖之间的背景图像库视图。这让我我想要的外观,但没有动画。
Right now, I have a Gallery view sandwiched between two LinearLayouts with tiled backgrounds. This gets me the look I want, but without the animation.
推荐答案
我终于想通了!希望这可以帮助别人。
I finally figured it out! Hopefully this can help someone.
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;
}
这篇关于安卓:滚动背景画廊的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文