0

画像と一緒にスクロールする背景を持つ水平方向の画像ギャラリーを作成しようとしています。基本的に、それはフィルムロール上の一連の写真のように見えることを意図しています。

これについてどうやって行くかについてのアイデアはありますか?誰かがこのようなことを試したことがありますか?

現在、タイル張りの背景を持つ2つのLinearLayoutに挟まれたギャラリービューがあります。これで私が望む外観になりますが、アニメーションはありません。

4

1 に答える 1

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;
    }
于 2012-05-29T16:32:30.773 に答える