1
我正在嘗試製作一個類似於android市場的畫廊,您可以滾動(左/右)來查看免費或付費應用程序等。 ..也可以通過佈局上下滾動。當試圖製作佈局畫廊時,文本顯示昏暗(最初)
到目前爲止,我只是加載了兩個佈局,它們有一個簡單的「Hello World!」文本視圖和「嗨!你好嗎?」文本視圖。
它們加載得很好,除了最初在畫廊的位置0處的文本顯示昏暗,直到我滾動並回到它。有什麼我失蹤了嗎?
public class HelloGallery extends Activity
{
@Override
public void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
Gallery gallery = (Gallery)findViewById(R.id.gallery);
gallery.setAdapter(new ViewAdapter(this));
gallery.setOnItemClickListener(new OnItemClickListener()
{
public void onItemClick(AdapterView<?> parent, View v, int position, long id)
{
Toast.makeText(HelloGallery.this, "" + position, Toast.LENGTH_SHORT).show();
}
});
}
}
public class ViewAdapter extends BaseAdapter
{
public Context mContext;
public static final Integer[] viewId = { R.layout.helloworld, R.layout.heyhowareyou };
public int mGalleryItemBackground;
public ViewAdapter(Context context)
{
this.mContext = context;
TypedArray attr = context.obtainStyledAttributes(R.styleable.HelloGallery);
mGalleryItemBackground = attr.getResourceId(R.styleable.HelloGallery_android_galleryItemBackground, 0);
attr.recycle();
}
@Override
public int getCount()
{
return viewId.length;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
convertView = LayoutInflater.from(mContext).inflate(viewId[position], null);
convertView.setLayoutParams(new Gallery.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
convertView.setBackgroundResource(mGalleryItemBackground);
return convertView;
}
}
我也引用了這一點。是什麼Aavon在這個線程是做正是我想要知道的...
主題鏈接:Get button to work in gallery with inflated layouts
任何幫助嗎?
在此先感謝。