
问候
阿努
嗨,感谢您的回复.我尝试使用gallery并实现了一个在其getVIEw方法中提供多视图的适配器.
我的java文件是:
public class GrIDvIEw extends Activity {@OverrIDepublic voID onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentVIEw(R.layout.main); gallery g = (gallery) findVIEwByID(R.ID.gallery); g.setAdapter(new GrIDAdapter(this)); g.setonItemClickListener(new OnItemClickListener() { public voID onItemClick(AdapterVIEw parent,VIEw v,int position,long ID) { Toast.makeText(GrIDvIEw.this,"" + position,Toast.LENGTH_SHORT).show(); } });}public class GrIDAdapter extends BaseAdapter { int mgalleryItemBackground; private Context mContext; private Integer[] mImageIDs = { R.drawable.icon,R.drawable.icon,}; public GrIDAdapter(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) { VIEw v; if(convertVIEw==null) { LayoutInflater li = getLayoutInflater(); v = li.inflate(R.layout.icon,null); ImageVIEw iv = (ImageVIEw)v.findVIEwByID(R.ID.icon_image); iv.setimageResource(R.drawable.icon); } else { v = convertVIEw; } return v; }}} main.xml是:
<?xml version="1.0" enCoding="utf-8"?> <gallery xmlns:androID="http://schemas.androID.com/apk/res/androID" androID:ID="@+ID/gallery" androID:layout_wIDth="fill_parent" androID:layout_height="wrap_content"/>
icon.xml是:
<?xml version="1.0" enCoding="utf-8"?><linearLayoutxmlns:androID="http://schemas.androID.com/apk/res/androID"androID:ID="@+ID/linearlayout"androID:layout_wIDth="fill_parent"androID:layout_height="fill_parent"androID:orIEntation="vertical"> <ImageVIEw androID:ID="@+ID/icon_image" androID:layout_wIDth="wrap_content" androID:layout_height="wrap_content" androID:orIEntation="vertical"> </ImageVIEw> </linearLayout>
我得到的输出是:http://www.4shared.com/photo/MzUcmzel/device.html
但这不是我真的需要.我想要不同行中的图标.任何帮助表示赞赏.
解决方法 我认为你最好的选择是使用一个gallery并实现一个在其getVIEw方法中提供多视图的适配器.请参阅 Hello Gallery并查看其中的ImageAdapter实现.例如,您可以扩展自己的自定义布局,例如具有垂直方向的linearLayout,而不是getVIEw在该示例中返回的ImageVIEw.
您可能会考虑在HorizontalScrollVIEw中使用tableLayout,但缺点是所有内容都会立即存在于内存中,从而难以扩展到大量项目. gallery回收了VIEws并提供了一些资源优势.
总结以上是内存溢出为你收集整理的android gridview中的水平滚动全部内容,希望文章能够帮你解决android gridview中的水平滚动所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)