在我的应用程序中,我需要在网格视图的单元格上执行翻转动画,以在用户触摸时显示另一个图像。最初我用图像填充网格视图,当用户触摸它们时,它们应该翻转,并向用户显示一些其他图像。提前感谢。 这是我的适配器类: -
public class Adapter extends BaseAdapter {
private Context mycontext;
public Integer[] picids = {
R.drawable.pic_1, R.drawable.pic_2, R.drawable.pic_3,
R.drawable.pic_4, R.drawable.pic_5, R.drawable.pic_6,
R.drawable.pic_7, R.drawable.pic_8, R.drawable.pic_9
};
public Adapter(Context c){
mycontext = c; }
@Override
public int getCount() {
// TODO Auto-generated method stub
return picids.length;
}
@Override
public Object getItem(int position) {
// TODO Auto-generated method stub
return picids[position];
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
return 0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
ImageView imageview = new ImageView(mycontext);
imageview.setImageResource(picids[position]);
imageview.setScaleType(ImageView.ScaleType.CENTER_CROP);
imageview.setLayoutParams(new GridView.LayoutParams(120,120));
return imageview ;
}
}
以下是我的主要活动类: -
public class MainActivity extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
GridView grid = (GridView)findViewById(R.id.grid_view);
grid.setAdapter(new Adapter(this));
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.main, menu);
return true;
}
}