2013-02-26 36 views
2

我已经使用Android通用图像加载器实现了我的gridview,但我需要在每张照片下面放置一个标签。 这是我ac_image_grid.xml在Android通用图像加载器中的图像下面实现GridView和文本

<?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; 
    } 

回答

2

也许是这样的;

private TextView mInfoView; 

OnCreate()

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

getView()

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