0

使用popupWindow mWindow.showAtLocation (view Gravity.NO_GRAVITY, -100, -100);

知道源代码中处理ViewManager的addView X <0, Y <0吗?

4

1 回答 1

1

此代码对我有用请尝试一下

    public void btnMyPicsClick(View v) {
    thredFlag = 1;
    outLineImage.setVisibility(View.INVISIBLE);
    saveImageAdapter = new SaveImageAdapter(DrawAppActivity.this);
    LayoutInflater inflater = (LayoutInflater) DrawAppActivity.this
            .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    DisplayMetrics displayMetrics = new DisplayMetrics();
    getWindowManager().getDefaultDisplay().getMetrics(displayMetrics);
    final PopupWindow popupWindow = new PopupWindow(inflater.inflate(
            R.layout.mypicturesgrid, null, false), 1230, 250, true);
    popupWindow.showAtLocation(findViewById(R.id.relativeLayoutBottom),
            Gravity.LEFT, 30, -240);
    View myPoppyView = popupWindow.getContentView();
    Button btnClose = (Button) myPoppyView.findViewById(R.id.btnColorClose);
    GridView gvOutLine = (GridView) myPoppyView
            .findViewById(R.id.gvOutline);
    gvOutLine.setAdapter(saveImageAdapter);
    gvOutLine.setOnItemClickListener(new OnItemClickListener() {
        @Override
        public void onItemClick(AdapterView<?> arg0, View v, int position,
                long id) {
            // TODO Auto-generated method stub
            String path = saveImageAdapter.fileName[position]
                    .getAbsolutePath();
            File file = new File(path);
            Uri uri = Uri.fromFile(file);
            myPicImageUri = Uri.fromFile(file);
            DisplayMetrics metrics = getApplicationContext().getResources()
                    .getDisplayMetrics();
            int w = metrics.widthPixels;
            int h = metrics.heightPixels;
            Bitmap bmp;
            try {
                bmp = BitmapFactory.decodeStream(getContentResolver()
                        .openInputStream(uri));
                Bitmap scaledBitmap = Bitmap.createScaledBitmap(bmp, w, h,
                        true);
                drawingSurface.setBitmap(scaledBitmap);
                drawingSurface.clear();
                popupWindow.dismiss();
            } catch (FileNotFoundException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    });
    btnClose.setOnClickListener(new OnClickListener() {
        @Override
        public void onClick(View v) {
            // TODO Auto-generated method stub
            popupWindow.dismiss();
        }
    });
}
于 2012-10-05T08:35:18.310 回答