WindowManager中的不可见视图,类型为RGBA_8888 ImageView

时间:2015-07-14 02:22:17

标签: android android-windowmanager

我经常使用该属性,但这次它不起作用。如果删除属性,我可以看到视图,一切正常。有人知道我错过了什么吗? mycode的:

    private boolean loadingDirect=false;
    private void addLoading(){
        loadingImg= new ImageView(mContext);
        android.view.WindowManager.LayoutParams viewParams = new android.view.WindowManager.LayoutParams();
        viewParams.x=0;
        viewParams.y=0;
        viewParams.width=600;
        viewParams.height=600;
//      viewParams.type=PixelFormat.RGBA_8888;
        loadingImg.setImageResource(R.drawable.notice_loading);
        loadingImg.setVisibility(View.VISIBLE);
        loadingDirect=true;
        loadingImg.setOnClickListener(new OnClickListener(){

            @Override
            public void onClick(View v) {
                if(loadingDirect){
                    Matrix matrix = new Matrix();
                    matrix.setRotate(180);
                    BitmapDrawable draw = (BitmapDrawable) mContext.getResources().getDrawable(R.drawable.notice_loading);
                    Bitmap bitmap= draw.getBitmap();
                    bitmap=Bitmap.createBitmap(bitmap,0, 0, bitmap.getWidth(),bitmap.getHeight(),matrix,true);
                    loadingImg.setImageBitmap(bitmap);
                    loadingDirect=false;
                }else{
                    loadingImg.setImageResource(R.drawable.notice_loading);
                    loadingDirect=true;
                }
            }

        });
        try{
            mWindowManager.addView(loadingImg, viewParams);
        }catch(Exception e){
            Log.d("NoticeBoardERROR", "addLoading");
        }
    }

1 个答案:

答案 0 :(得分:0)

请查看http://developer.android.com/reference/android/view/WindowManager.LayoutParams.html

您的viewParams.type不期望PixelFormat.RGBA_8888或PixelFormat.whatever;你的代码编译只是因为它们实际上是int数字。但这不是预期的行为。