0

http://developer.android.com/training/displaying-bitmaps/index.htmlで提供されているビットマップ コードを実装しようとしています。すべてのサムネイル画像の近くに画像名を追加したいだけです.テキストビューを追加するにはどうすればよいですか? これを達成する方法はありますか?

コードの getview メソッド

  @Override
    public View getView(int position, View convertView, ViewGroup container) {
        // First check if this is the top row
        if (position < mNumColumns) {
            if (convertView == null) {
                convertView = new View(mContext);
            }
            // Set empty view with height of ActionBar
            convertView.setLayoutParams(new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, mActionBarHeight));
            return convertView;
        }

        // Now handle the main ImageView thumbnails
        ImageView imageView;
        TextView  textView;
        if (convertView == null) { // if it's not recycled, instantiate and initialize
            imageView = new RecyclingImageView(mContext);
            imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
            imageView.setLayoutParams(mImageViewLayoutParams);
            imageView.setPadding(20, 20, 20, 20);


        } else { // Otherwise re-use the converted view
            imageView = (ImageView) convertView;
        }

        // Check the height matches our calculated column width
        if (imageView.getLayoutParams().height != mItemHeight) {
            imageView.setLayoutParams(mImageViewLayoutParams);
        }

        // Finally load the image asynchronously into the ImageView, this also takes care of
        // setting a placeholder image while the background thread runs
        mImageFetcher.loadImage(Images.imageThumbUrls[position - mNumColumns], imageView);
        return imageView;
    }
4

3 に答える 3

0

そんな風習をつくります。

public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;

        if (convertView == null || convertView.getTag() == null) {
            holder = new ViewHolder();
            convertView = mInflater.inflate(R.layout.custom_row, null);
            holder.image = (ImageView) convertView.findViewById(R.id.image_List);
            holder.url = (TextView) convertView.findViewById(R.id.text_List);

            convertView.setTag(holder);

        }

                 holder.url.setText("use name");
            if (bitmap != null) {               
                // image download now compress and set on Image view
                bitmap = Bitmap.createScaledBitmap(bitmap, 60, 60, true);
                imageView.setImageBitmap(bitmap);
            }           



        return convertView;
    }

    private static class ViewHolder {
        ImageView image;

        TextView url;
    }
于 2013-05-27T09:37:47.930 に答える
0

Linearlayout を外側にラップする

@Override
    public View getView(int position, View convertView, ViewGroup container) {
        // First check if this is the top row
        if (position < mNumColumns) {
            if (convertView == null) {
                convertView = new View(mContext);
            }
            // Set empty view with height of ActionBar
            convertView.setLayoutParams(new AbsListView.LayoutParams(
                    ViewGroup.LayoutParams.MATCH_PARENT, mActionBarHeight));
            return convertView;
        }

    // Now handle the main ImageView thumbnails
     LinearLayout layout=new LinearLayout(context);
    layout.add(imageView);
   layout.add(textView) 

    ImageView imageView;
    TextView  textView;
    if (convertView == null) { // if it's not recycled, instantiate and initialize
        imageView = new RecyclingImageView(mContext);
        imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
        imageView.setLayoutParams(mImageViewLayoutParams);
        imageView.setPadding(20, 20, 20, 20);


    } else { // Otherwise re-use the converted view
        converView= (ImageView) layout;
    }

    // Check the height matches our calculated column width
    if (imageView.getLayoutParams().height != mItemHeight) {
        imageView.setLayoutParams(mImageViewLayoutParams);
    }

    // Finally load the image asynchronously into the ImageView, this also takes care of
    // setting a placeholder image while the background thread runs
    mImageFetcher.loadImage(Images.imageThumbUrls[position - mNumColumns], imageView);
    return layout;
}
于 2013-05-27T09:35:46.250 に答える