Android:在图库中滚动背景

时间:2012-05-29 01:52:50

标签: android animation gallery

我正在尝试创建一个水平图库,其背景与图像一起滚动。基本上,它意味着看起来就像电影胶卷上的一系列图片。

有什么想法可以解决这个问题吗?有没有人尝试过这样的事情?

现在,我有一个夹在两个带有平铺背景的LinearLayouts之间的图库视图。这让我看起来像我想要的,但没有动画。

1 个答案:

答案 0 :(得分:0)

我终于明白了!希望这可以帮助某人。

    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;
    }