我有自定义适配器的ListView。问题是,图库视图非常高,尽管layout_height中有wrap_content。我怎么解决它?
public class ListViewAdapter extends BaseAdapter {
Context ctx;
LayoutInflater lInflater;
Integer[] objects;
ListViewAdapter(Context context, Integer[] images) {
ctx = context;
objects = images;
lInflater = (LayoutInflater) ctx
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
}
@Override
public int getCount() {
return objects.length;
}
@Override
public Object getItem(int position) {
return objects[position];
}
@Override
public long getItemId(int position) {
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
if (position==1){
View galleryView =lInflater.inflate(R.layout.galerry_view,parent,false);
final Gallery gallery = (Gallery) galleryView.findViewById(R.id.gallery1);
gallery.setAdapter(new ImageAdapter(ctx));
return galleryView;
}
ImageView view=new ImageView(ctx);
view.setImageResource(objects[position]);
return view;
}
}
正如您所看到的,当位置== 1时,它会使图库膨胀。 有galerry xml布局和图库适配器:
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery1"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
图库适配器&#34; ImageAdapter&#34;:
public class ImageAdapter extends BaseAdapter {
private int mGalleryItemBackground;
private Context mContext;
private final Integer[] mImage = {R.drawable.tmp_poster1, R.drawable.tmp_poster2};
public ImageAdapter(Context ctx){
mContext=ctx;
}
@Override
public int getCount() {
return mImage.length;
}
@Override
public Object getItem(int position) {
return mImage[position];
}
@Override
public long getItemId(int position) {
return mImage[position];
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
ImageView view = new ImageView(mContext);
view.setImageResource(mImage[position]);
view.setPadding(20, 20, 20, 20);
view.setScaleType(ImageView.ScaleType.FIT_CENTER);
return view;
}
}