资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

GridView的使用-创新互联

创新互联基于分布式IDC数据中心构建的平台为众多户提供西部信息机房 四川大带宽租用 成都机柜租用 成都服务器租用。>public class MainActivity extends Activity { private GridView gridView; private int[] images = {R.drawable.img_item0,R.drawable.img_item1 ,R.drawable.img_item2,R.drawable.img_item3,R.drawable.img_item4, R.drawable.img_item5,R.drawable.img_item6,R.drawable.img_item7, R.drawable.img_item8}; private String[] desc = {"该减肥了","该运动运动了","","","","","","",""}; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.gridview); gridView= (GridView) findViewById(R.id.gv); MyAdapter adapter= new MyAdapter(images,desc); gridView.setAdapter(adapter); gridView.setOnItemClickListener(new OnItemClickListener() { @Override public void onItemClick(AdapterView parent, View view, int position, long id) { Animation anim= new TranslateAnimation(-2, 2, 0, 0,Animation.RELATIVE_TO_SELF,0.5f,Animation.RELATIVE_TO_SELF,0.5f); anim.setDuration(1000); anim.setRepeatCount(3); anim.setRepeatMode(Animation.REVERSE); ImageView image= (ImageView) view.findViewById(R.id.image); image.setAnimation(anim); anim.start(); } }); } class MyAdapter extends BaseAdapter{ int[] imgItemRes; String[] imgItemDesc; public MyAdapter(int[] imgItemRes,String[] imgItemDesc){ this.imgItemRes = imgItemRes; this.imgItemDesc = imgItemDesc; } @Override public int getCount() { return imgItemRes.length; } @Override public Object getItem(int position) { return null; } @Override public long getItemId(int position) { return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { if(convertView==null){ LayoutInflater inflater= getLayoutInflater(); convertView= inflater.inflate(R.layout.gridviewitem, null); } ImageView image= (ImageView) convertView.findViewById(R.id.image); TextView text= (TextView) convertView.findViewById(R.id.text); image.setImageResource(imgItemRes[position]); text.setText(imgItemDesc[position]); return convertView; } } } gridview.xml
    

gridviewitem.xml
    
GridView的使用
新闻名称:GridView的使用-创新互联
分享URL:http://cdkjz.cn/article/dpshsg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220