我正在尝试以编程方式将自定义视图添加到自定义适配器中的图像列表视图中。目前我正在尝试将其添加为第三个“图像”。我的客户适配器不稳定,所以不知道如何让它工作。填充所有图像是完美的,但不能在那之间获得广告空间。有什么建议吗?
@Override
public View getView(int position, View convertView, ViewGroup parent) {
View rowView = convertView;
if (rowView == null) {
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
rowView = inflater.inflate(R.layout.image_row, null);
ViewHolder viewHolder = new ViewHolder();
if(position==3) {
adSpace = new AdSpace(context, "c026dd7e-60a5-46c9-948f-38eb18a", true);
adSpace.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
Log.i("AdSpace","Adding adspace");
} else {
viewHolder.image = (ImageView) rowView.findViewById(R.id.offer_row);
}
rowView.setTag(viewHolder);
}
ViewHolder holder = (ViewHolder) rowView.getTag();
imageLoader.displayImage(imageURLArray.get(position), holder.image, options);
return rowView;
}
static class ViewHolder {
public ImageView image;
public AdSpace adspace;
}
list.xml:
<?xml version="1.0" encoding="utf-8"?>
<"packagename".ZoomView xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<ListView
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="@+id/offer_list" />
image_row.xml:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res/"packagename""
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<ImageView
android:id="@+id/offer_row"
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:contentDescription="Image" />
答案 0 :(得分:1)
您正在创建adSpace但从未使用它。
if(position==3) {
adSpace = new AdSpace(context, "c026dd7e-60a5-46c9-948f-38eb18a", true);
adSpace.setLayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT));
Log.i("AdSpace","Adding adspace");
return adSpace;
}
您可以从视图中删除adSpace。