2

我已经使用 Android Universal Image Loader 实现了我的 gridview,但我需要在每张照片下方放置一个标签。这是我的 ac_image_grid.xml

<?xml version="1.0" encoding="utf-8"?>
<GridView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gridview"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center"
android:horizontalSpacing="4dip"
android:numColumns="3"
android:stretchMode="columnWidth"
android:verticalSpacing="4dip"
android:padding="4dip" />

这是我的 item_grid_image.xml :

<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/widget44"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_x="201px"
android:layout_y="165px"
android:gravity="center_horizontal"
>
<ImageView 
android:id="@+id/image"
android:layout_width="fill_parent"
android:layout_height="120dip"
android:adjustViewBounds="true"
android:contentDescription="@string/descr_image"
android:scaleType="centerCrop" />
<TextView
android:id="@+id/icon_text"
android:typeface="serif"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:textStyle="bold"
android:lines="2">
</TextView>
</LinearLayout>

我知道我必须在这个函数中实现它,但我不知道如何:

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        final ImageView imageView;
        if (convertView == null) {
            imageView = (ImageView) getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
        } else {
            imageView = (ImageView) convertView;
        }

        imageLoader.displayImage(imageUrlsSmall.get(position), imageView, options);

        return imageView;
    }

更新:最后我用这段代码做到了。

    public View getView(final int position, View convertView, ViewGroup parent) {
        View view = convertView;
        final ViewHolder holder;
        if (convertView == null) {
            view = getLayoutInflater().inflate(R.layout.item_grid_image, parent, false);
            holder = new ViewHolder();
            holder.text = (TextView) view.findViewById(R.id.icon_text);
            holder.image = (ImageView) view.findViewById(R.id.image);
            view.setTag(holder);
        } else {
            holder = (ViewHolder) view.getTag();
        }

        holder.text.setText(album[position].getName());

        imageLoader.displayImage(albumsPhoto[position], holder.image, options, animateFirstListener);

        return view;
    }
4

1 回答 1

2

也许是这样的;

 private TextView mInfoView;

OnCreate()

 mInfoView = (TextView) findViewById(R.id.icon_text);

getView()

 // after imageLoader.displayImage
 mInfoView.setBackgroundColor(Color.TRANSPARENT);
 mInfoView.setText("Some description");
于 2013-02-26T02:14:43.680 回答