重庆分公司,新征程启航
为企业提供网站建设、域名注册、服务器等服务
创新互联基于分布式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