簡體   English   中英

在WindowManager中對ImageView進行動畫處理-Android

[英]Animate ImageView inside WindowManager - Android

我想在WindowManager中為ImageView設置動畫。 但這是行不通的。 請在下面找到我的代碼。 在這里您可以看到我獲得了窗口管理器系統服務並添加了imageview。 現在我試圖在窗口管理器中添加imageview之后旋轉。

在一個活動中它工作正常。



    public class FloatingImageAnimationService extends Service {

        private WindowManager windowManager;
        private static ImageView chatHead;

        @Override
        public IBinder onBind(Intent arg0) {
            // TODO Auto-generated method stub
            return null;
        }
     @Override 
         public void onCreate() {
             super.onCreate();
             windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

             chatHead = new ImageView(this);

             chatHead.setImageResource(R.drawable.image_small);


             final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                             WindowManager.LayoutParams.WRAP_CONTENT,
                             WindowManager.LayoutParams.WRAP_CONTENT,
                             WindowManager.LayoutParams.TYPE_PHONE,
                             WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                             PixelFormat.TRANSLUCENT);


             params.gravity = Gravity.TOP | Gravity.LEFT;
             params.x = 0;
             params.y = 100;

             windowManager.addView(chatHead, params);


             RotateAnimation ra = new RotateAnimation(
                    0, 
                    -80,
                    Animation.RELATIVE_TO_SELF, 0.5f, 
                    Animation.RELATIVE_TO_SELF,
                    0.5f);

            // how long the animation will take place
            ra.setDuration(210);

            // set the animation after the end of the reservation status
            ra.setFillAfter(true);
            // Start the animation
            chatHead.startAnimation(ra);
         }
    }

請讓我知道要使其正常工作還需要執行哪些其他步驟。

謝謝,

比卡什

您可以通過添加類似這樣的布局來制作動畫。

//..at your onCreate() method
super.onCreate();
windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);

chatHead = new ImageView(this);
chatHead.setImageResource(R.drawable.image_small);

// Create an additional layout for your animation.
LinearLayout layout = new LinearLayout(this);
layout.addView(chatHead); // And attach your objects 

final WindowManager.LayoutParams params = new WindowManager.LayoutParams(
                         WindowManager.LayoutParams.WRAP_CONTENT,
                         WindowManager.LayoutParams.WRAP_CONTENT,
                         WindowManager.LayoutParams.TYPE_PHONE,
                         WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                         PixelFormat.TRANSLUCENT);


params.gravity = Gravity.TOP | Gravity.LEFT;
params.x = 0;
params.y = 100;

// Add your layout to the windowManager instead of your object.
windowManager.addView(layout, params); 

//.. Add animations what you want.

當我遭受完全相同的案件時,它對我有用。

設置此權限:

<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM