Android控件gridview实现单行多列横向滚动效果
本文实例为大家分享了安卓实现单行多列横向滚动,供大家参考,具体内容如下
指定其中LinearLayout的宽度就能够实现你GridView的长宽变化,如果它的长超过屏幕,则自动添加水平滚动条。
privateint[]icon={R.drawable.camera,R.drawable.wifi,R.drawable.temperature, R.drawable.lamp,R.drawable.wechat,R.drawable.mic,}; privateString[]iconName={"摄像头","网络","温湿度","电器","微信","语音"}; privateGridViewgview; privateList
Fragment里:
oncreate里边初始化数据,oncreateview里边初始化gridview和绑定适配器
publicViewonCreateView(LayoutInflaterinflater,ViewGroupcontainer, BundlesavedInstanceState){ //TODOAuto-generatedmethodstub Viewview=inflater.inflate(R.layout.gridview,container,false); gridview=(GridView)view.findViewById(R.id.gridview1); //新建List data_list=newArrayList>(); //http://www.cnblogs.com/xiaobo-Linux/qq463431476 //获取数据 getData(); //新建适配器 String[]from={"image","text"}; int[]to={R.id.image,R.id.title}; sim_adapter=newSimpleAdapter(getActivity(),data_list,R.layout.items,from,to); //配置适配器 gridview.setAdapter(sim_adapter); returnview; }
publicvoidonCreate(BundlesavedInstanceState){ super.onCreate(savedInstanceState); } //http://www.cnblogs.com/xiaobo-Linux/qq463431476 publicList>getData(){ //cion和iconName的长度是相同的,这里任选其一都可以 for(inti=0;i map=newHashMap (); map.put("image",icon[i]); map.put("text",iconName[i]); data_list.add(map); } returndata_list; }
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持毛票票。