在我的应用程序中,我需要在 GridView 的单元格上执行翻转动画,以便在用户触摸时显示另一幅图像。最初我用图像填充了 GridView ,当用户触摸它们时,它们应该翻转并向用户显示一些其他图像。提前致谢。 这是我的适配器类:-
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 ;
}
以下是我的主要 Activity 类(class):-
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;
}
最佳答案
一个相对 hacky 的方法是使用 JazzyListView ,并从源代码中“抓取”一个动画并在您的 onClick 监听器中实现它以触发动画事件。
关于android - 如何在触摸时翻转每个 GridView 单元格并显示另一张图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22777314/