我有一個動態imageview的相機圖片,我的問題是我想在我選擇的imageview上設置刻度線。請幫幫我。如何在imageview上設置imageview?
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
setContentView(R.layout.headshotallphoto);
dbHeadshot = new DataHelperHeadshot(this);
DisplayMetrics displaymetrics = new DisplayMetrics();
getWindowManager().getDefaultDisplay().getMetrics(displaymetrics);
ht = displaymetrics.heightPixels;
wt = displaymetrics.widthPixels;
GridView imagegrid = (GridView) findViewById(R.id.PhoneImageGrid);
imagegrid.setAdapter(new ImageAdapter(getApplicationContext(),bmp));
imagegrid.setOnItemClickListener(this);
}
public class ImageAdapter extends BaseAdapter
{
private Context mContext;
private Bitmap[] mImageArray;
public ImageAdapter(Context c, Bitmap[] imgArray)
{
mContext = c;
mImageArray = imgArray;
}
public int getCount()
{
return mImageArray.length;
}
public Object getItem(int position)
{
return position;
}
public long getItemId(int position)
{
return position;
}
public View getView(int position,View convertView,ViewGroup parent)
{
System.gc();
ImageView i = null ;//= new ImageView(mContext.getApplicationContext());
if (convertView == null)
{
i = new ImageView(mContext);
i.setLayoutParams(new GridView.LayoutParams(92,92));
i.setScaleType(ImageView.ScaleType.CENTER_CROP);
i.setPadding(8, 8, 8, 8);
i.setImageBitmap(mImageArray[position]);
}
else
i = (ImageView) convertView;
return i;
}
}
public Bitmap decodeFile(String filePath)
{
BitmapFactory.Options o = new BitmapFactory.Options();
o.inJustDecodeBounds = true;
BitmapFactory.decodeFile(filePath, o);
// The new size we want to scale to
final int REQUIRED_SIZE = 100;
final int H = 50;
// Find the correct scale value. It should be the power of 2.
int width_tmp = o.outWidth, height_tmp = o.outHeight;
int scale = 1;
while (true) {
if (width_tmp < REQUIRED_SIZE && height_tmp < H)
break;
width_tmp /= 2;
height_tmp /= 2;
scale *= 2;
}
// Decode with inSampleSize
BitmapFactory.Options o2 = new BitmapFactory.Options();
o2.inSampleSize = scale;
bitmap = BitmapFactory.decodeFile(filePath, o2);
return bitmap;
}
public void onItemClick(AdapterView<?> a, View v, int position, long id)
{
ImageView tickmark = new ImageView(this);
tickmark.setBackgroundResource(R.drawable.imgredselectmark);
}
感謝jaydeep的幫助,但我想從網格視圖中的選定圖片上設置勾號。而我不知道如何把刻度線放在選定的圖片上。請幫助,我需要緊急做 – Monali 2011-05-13 12:07:41
謝謝,但這段代碼不幫我 – Monali 2011-05-13 13:54:57
沒問題...會幫助其他人:) – 2011-05-13 13:56:21