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的使用-创新互联
分享路径:http://ptjierui.cn/article/dpshsg.html

其他资讯

Copyright © 2024 青羊区广皓图文设计工作室(个体工商户)(郫都区郫县站) All Rights Reserved 蜀ICP备19037934号
友情链接: 成都企业网站建设 营销型网站建设 专业网站设计 定制网站建设多少钱 高端网站设计推广 营销网站建设 达州网站设计 营销网站建设 成都网站建设推广 高端网站设计 营销型网站建设 网站建设推广 成都网站建设公司 网站建设方案 网站建设公司 成都网站建设 成都模版网站建设 自适应网站设计 成都网站建设 成都网站建设 成都网站制作 手机网站制作设计