android - 在 Android 通用图像加载器中实现 GridView 并在图像下方添加文本

标签 android universal-image-loader

我已经使用 Android 通用图像加载器实现了 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;
    }

最佳答案

也许是这样的;

 private TextView mInfoView;

OnCreate():

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

getView():

 // after imageLoader.displayImage
 mInfoView.setBackgroundColor(Color.TRANSPARENT);
 mInfoView.setText("Some description");

关于android - 在 Android 通用图像加载器中实现 GridView 并在图像下方添加文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15080007/

相关文章:

android - 使用通用图像加载器内存不足错误查看寻呼机

java - 难以增加和减少生命

Android测试找不到源类

android - Android 版 Google map 上的自定义相机动画

Android NDK 混合 C 和 C++ 错误未定义对 mult(int, int) 的引用

java - uri 获取错误的文件路径

java - 通用图像加载器 imageview 不会使用微调器自行更新

android - ListView 图像仅在可见时显示

android - 通用图像加载器 Android : Changing Layout properties causes OutOfMemoryError

Android PagerAdapter::获取当前项目到位图中