【问题标题】:How to show a gallery in a tabbed screen?如何在选项卡式屏幕中显示画廊?
【发布时间】:2011-12-22 11:01:37
【问题描述】:

我正在尝试制作一个带有显示列表活动的选项卡的应用程序,并在第二个选项卡上显示一个画廊。 第一个似乎工作,但我怎样才能制作第二个?我使用了来自 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;
}
}
}

请帮忙?

【问题讨论】:

  • 我不明白为什么运行画廊的选项卡式活动不能正常工作。如果您发布代码会更容易提供帮助。
  • 显然您发布的代码没有任何问题,似乎您使用了 HelloGallery 中的示例代码并且您正在正确创建您的选项卡(假设它已被初始化)。刚刚注意到你没有使用 android.R.styleable;您是否将组件复制到 res/ 文件夹?此外,这可能是 XML 的问题。
  • 是的,我遇到了问题!感谢您的帮助!我浪费了一整天的时间!
  • 请检查[this][1]。我认为您想将画廊添加到第二个选项卡。 [1]:stackoverflow.com/questions/10227115/…

标签: android android-layout android-gallery


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-08
    • 1970-01-01
    相关资源
    最近更新 更多