Android实现GridView中ImageView动态变换的方法

2019-12-10 19:59:53刘景俊
  • }  final TextView textView = (TextView) convertView;//.findViewById(R.id.mygrid); 
  • textView.setTag(item);  textView.setText(item.text); 
  • textView.setCompoundDrawablesWithIntrinsicBounds(null, item.image, null, null);  textView.setOnTouchListener(new OnTouchListener(){ 
  • public boolean onTouch(View arg0, MotionEvent arg1) {  // TODO Auto-generated method stub 
  • if (arg1.getAction() == MotionEvent.ACTION_DOWN){  Log.d("WeatherWidget", MotionEvent.ACTION_DOWN+""); 
  • textView.setCompoundDrawablesWithIntrinsicBounds(null, item.touchimage, null, null);  } 
  • else if(arg1.getAction() == MotionEvent.ACTION_UP) {  Log.d("WeatherWidget", arg1.getAction()+""); 
  • textView.setCompoundDrawablesWithIntrinsicBounds(null, item.image, null, null);  Intent i = new Intent(MainActivity.this,Page1Activity.class); 
  • startActivity(i);  } 
  • return true;  } 
  • });  return convertView; 
  • }  public int getCount() { 
  • return mItems.size();  } 
  • public Object getItem(int position) {  return mItems.get(position); 
  • }  public long getItemId(int position) { 
  • return position;  } 
  • }  } 

    main.xml代码:

     

     
    1. <?xml version="1.0" encoding="utf-8"?>  <LinearLayout xmlns:android="http://www.easck.com/apk/res/android"