如何在标签屏幕中显示图库?

时间:2011-12-22 11:01:37

标签: android android-layout android-gallery

我正在尝试使用显示listactivity的标签创建应用,并在第二个标签上创建一个图库。 第一个似乎工作,但我怎么能做第二个?我已经使用了android的教程,但那些没有工作。有人帮忙吗?

这是标签:

    host.addTab(host.newTabSpec("tab4")
            .setIndicator("Images")
            .setContent(new Intent(this,Images.class)));

活动:

    public class Images extends Activity
{  @Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Gallery g = (Gallery) findViewById(R.id.gallery);
g.setAdapter(new ImageAdapter(this));
 }

 public class ImageAdapter extends BaseAdapter {
  int mGalleryItemBackground;
 private Context mContext;

 private Integer[] mImageIds = {
    R.drawable.icon,
    R.drawable.icon,
    R.drawable.icon
  };

 public ImageAdapter(Context c) {
 mContext = c;
 TypedArray a = obtainStyledAttributes(R.styleable.HelloGallery);
 mGalleryItemBackground = a.getResourceId(
        R.styleable.HelloGallery_android_galleryItemBackground, 0);
 a.recycle();
   }

  public int getCount() {
  return mImageIds.length;
   }

public Object getItem(int position) {
return position;
 }

public long getItemId(int position) {
return position;
 }

public View getView(int position, View convertView, ViewGroup parent) {
ImageView i = new ImageView(mContext);

i.setImageResource(mImageIds[position]);
i.setLayoutParams(new Gallery.LayoutParams(150, 100));
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setBackgroundResource(mGalleryItemBackground);

return i;
}
}
}

请帮帮忙?

1 个答案:

答案 0 :(得分:0)

检查this TabContentFactory 可以为您提供解决方案。