程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 更多編程語言 >> 編程綜合問答 >> android-在 imageview 上面設置 imageview

android-在 imageview 上面設置 imageview

編輯:編程綜合問答
在 imageview 上面設置 imageview

在camera picture上有一個動態的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);
}

最佳回答:


使用 Frame layout:

<FrameLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:orientation="vertical"
        android:padding="5dip">
        <ImageView
    android:id="@+id/image_check"
            android:orientation="vertical"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
            android:src="@drawable/tick"/>
                <ImageView
                android:id="@+id/imageview"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:src="@drawable/image">

在 GridView 中

gridview.setOnItemClickListener(new OnItemClickListener(){
    @Override
    public void onItemClick(AdapterView<?> parent, final View view, final int position,
                long id) {
            view.setOnClickListener(new View.OnClickListener(){
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
if(view.findViewById(R.id.image_check).getVisibility==ImageView.VISIBLE)
   {
view.findViewById(R.id.image_check).setVisibility(ImageView.VISIBLE)
   }
  else
  {
view.findViewById(R.id.image_check).setVisibility(ImageView.GONE)
  }
}
}
});
  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved