0

タイル状の背景を含むレイアウトで、ギャラリー内のImageViewの上部と下部を囲むようにしています。上部は機能しているようですが、下部のレイアウトは表示されません。なぜ何かアイデアはありますか?これが私のgetView()です:

public View getView(int position, View convertView, ViewGroup parent) {
            RelativeLayout container = new RelativeLayout(galleryContext);

            RelativeLayout topReel = new RelativeLayout(galleryContext);
            RelativeLayout bottomReel = new RelativeLayout(galleryContext);

            topReel.setBackgroundResource(R.drawable.film_top);
            bottomReel.setBackgroundResource(R.drawable.film_bottom);

            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.setBackgroundResource(galleryBackground);

            RelativeLayout.LayoutParams topParams = new RelativeLayout.LayoutParams(imageSizeInPixels, 20);
            topParams.addRule(RelativeLayout.ABOVE, imageView.getId());
            topParams.addRule(RelativeLayout.CENTER_HORIZONTAL);


            RelativeLayout.LayoutParams bottomParams = new RelativeLayout.LayoutParams(imageSizeInPixels, 20);
            bottomParams.addRule(RelativeLayout.BELOW, imageView.getId());
            bottomParams.addRule(RelativeLayout.CENTER_HORIZONTAL);

            RelativeLayout.LayoutParams imageParams = new RelativeLayout.LayoutParams(imageSizeInPixels, imageSizeInPixels);
            imageParams.addRule(RelativeLayout.BELOW, topReel.getId());
            imageParams.addRule(RelativeLayout.ABOVE, bottomReel.getId());
            imageParams.addRule(RelativeLayout.CENTER_VERTICAL);
            imageParams.addRule(RelativeLayout.CENTER_HORIZONTAL);


            container.addView(topReel, topParams);
            container.addView(bottomReel, bottomParams);
            container.addView(imageView, imageParams);

            return container;
        }
4

1 に答える 1

0

これは問題を解決します、うまくいけば誰かがこれを使うことができます:

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(), ((int)(imageSizeInPixels * .75)));

            //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-07-19T14:44:33.477 に答える