我想顯示來自RSS-Feed的一些圖像數據。我的RSS源代碼工作正常,圖像也從源正確加載,但我無法以水平方式顯示圖像?我試圖與畫廊,但無法將圖像放入?有什麼辦法可以達到同樣的效果嗎?水平顯示項目?
我也參考鏈接http://www.dev-smart.com/archives/34來實現水平ListView,但在那我無法實現onClickListener的列表。請任何幫助。謝謝。
我嘗試了畫廊的代碼..
公共類ImageAdapter延伸BaseAdapter {
int imageBackground;
private List<RSSIteam> objects = null;
private Context context;
public ImageAdapter(Context c)
{
context = c;
TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
ta.recycle();
}
public ImageAdapter(Context context, int textViewResourceId, List<RSSIteam> objects)
{
super();
this.context = context;
this.objects = objects;
}
@Override
public int getCount()
{
return this.objects.size();
//return pics.length;
}
@Override
public Object getItem(int position)
{
return this.objects.get(position);
//return position;
}
@Override
public long getItemId(int position)
{
return position;
}
@Override
public View getView(int position, View convertView, ViewGroup parent)
{
RSSIteam data = (RSSIteam) getItem(position);
String imageUrl = data.imageurl;
try
{
URL feedImage = new URL(imageUrl);
HttpURLConnection conn= (HttpURLConnection)feedImage.openConnection();
InputStream is = conn.getInputStream();
Bitmap img = BitmapFactory.decodeStream(is);
}
catch (MalformedURLException e)
{
e.printStackTrace();
}
catch (IOException e)
{
e.printStackTrace();
}
ImageView iv = new ImageView(context);
iv.setImageResource(img[position]); //here i am unable to set the image in particular position because it require int type array
iv.setScaleType(ImageView.ScaleType.FIT_XY);
iv.setLayoutParams(new Gallery.LayoutParams(90,70));
iv.setBackgroundResource(imageBackground);
return iv;
}
}
「我試着用圖片庫,但不能把圖像成.. ???」 - 發佈你的代碼。 – user370305 2012-02-02 09:43:05