package android.test.draw2d;
import android.app.Activity;
import android.content.Context;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.Gallery;
import android.widget.ImageView;
public class Draw2dActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
((Gallery)findViewById(R.id.gallery1)).setAdapter(new ImageAdapter(this));
}
public class ImageAdapter extends BaseAdapter
{
Context mycontext;
private final String tag="ImageAdapter-may";
private int[] myImageIds=
{
android.R.drawable.btn_minus,
android.R.drawable.btn_radio,
android.R.drawable.ic_lock_idle_low_battery,
android.R.drawable.ic_menu_camera
};
public ImageAdapter(Context c){this.mycontext=c;}
@Override
public int getCount() {
// TODO Auto-generated method stub
Log.d(tag, "getCount="+this.myImageIds.length);
return this.myImageIds.length;
}
@Override
public Object getItem(int arg0) {
// TODO Auto-generated method stub
Log.d(tag, "getItem="+arg0);
return arg0;
}
@Override
public long getItemId(int arg0) {
// TODO Auto-generated method stub
Log.d(tag, "getItemId="+arg0);
return arg0;
}
@Override
public View getView(int position, View convertView, ViewGroup parent) {
// TODO Auto-generated method stub
Log.d(tag, "getView");
ImageView i=new ImageView(this.mycontext);
i.setImageResource(this.myImageIds[position]);
i.setScaleType(ImageView.ScaleType.FIT_XY);
i.setLayoutParams(new Gallery.LayoutParams(120,120));
return i;
}
public float getScale(boolean focussed,int offset)
{
Log.d(tag, "getScale");
return Math.max(0,1.0f/(float)Math.pow(2, Math.abs(offset)));
}
}
}
Gallery应用
最新推荐文章于 2024-08-26 20:49:22 发布