标签: android-windowmanager

无法删除windowManager.addView()附加的视图

我正在尝试删除添加到WindowManager的图层.但是当我调用removeView()时没有任何反应.有人知道如何删除它吗?我的代码看起来像这样.

public class MainActivity extends Activity implements View.OnClickListener{

    private WindowManager wm;
    private  WindowManager.LayoutParams orientationLayout;
    private LinearLayout orientationChanger;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        // init landscape things
        wm = (WindowManager) getApplicationContext().getSystemService(Service.WINDOW_SERVICE);
        orientationChanger = new LinearLayout(getApplicationContext());
        orientationChanger.setClickable(false);
        orientationChanger.setFocusable(false);
        orientationChanger.setFocusableInTouchMode(false);
        orientationChanger.setLongClickable(false);
        orientationLayout = new WindowManager.LayoutParams(
                WindowManager.LayoutParams.WRAP_CONTENT, WindowManager.LayoutParams.WRAP_CONTENT,
                WindowManager.LayoutParams.TYPE_SYSTEM_ERROR,
                WindowManager.LayoutParams.FLAG_NOT_TOUCH_MODAL
                        | WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE,
                PixelFormat.RGBA_8888);
        orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;

        // set view
        setContentView(R.layout.calibrate);

        findViewById(android.R.id.button).setOnClickListener(this);

        lockLandScape();
    }

    public void lockLandScape(){
        wm.addView(orientationChanger, orientationLayout);

        orientationChanger.setVisibility(View.GONE);
        orientationLayout.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
        wm.updateViewLayout(orientationChanger, orientationLayout);
        orientationChanger.setVisibility(View.VISIBLE);
    }

    public void releaseLandScape(){
        wm.removeView(orientationChanger);

        // This …
Run Code Online (Sandbox Code Playgroud)

android android-layout android-view android-windowmanager

4
推荐指数
1
解决办法
8692
查看次数

Facebook Messenger如何绘制聊天记录?(机器人)

我知道在StackOverflow上已经有很多次问过这个问题了,但我很着迷Facebook Messenger如何绘制Chatheads.

我按照本教程将ImageView作为叠加层放置.然而,拖动它是非常缓慢的,不像Chatheads显示非常流畅的动画.

在拖动Chathead时,启用"开发者"选项中的"显示GPU视图更新"选项会闪烁屏幕.但是,拖动我的ImageView不会触发任何闪烁.

这是一个小小的截屏视频:https://dl.dropboxusercontent.com/u/13595927/temp/TRIM_20140225_134543.mp4

我尝试将图层类型设置为LAYER_TYPE_SOFTWARE,但它没有改变任何东西.我还缺少什么?

android facebook android-layout android-imageview android-windowmanager

4
推荐指数
1
解决办法
2810
查看次数

键盘可见后,Android WindowManager窗口不会重新定位

屏幕上显示的窗口

public class FlatingViewService extends Service{
      public static WindowManager windowManager;
              ...

    windowManager = (WindowManager) getSystemService(WINDOW_SERVICE);
     ...

    //Floating View Layout
   li = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);

   myView = li.inflate(R.layout.product_response_card, null);

  name =  (TextView) myView.findViewById(R.id.name);

  editTextName = (TextView) myView.findViewById(R.id.editTextName);
    ...

    //Layout Parameters
    ...
   response_card_params.softInputMode =  WindowManager.LayoutParams.SOFT_INPUT_ADJUST_RESIZE | WindowManager.LayoutParams.SOFT_INPUT_STATE_VISIBLE;
Run Code Online (Sandbox Code Playgroud)

当用户尝试在editText中输入一些文本时,键盘会出现在editText的顶部.所以用户看不到任何东西.

什么是实际问题?

android window-managers android-service android-windowmanager

3
推荐指数
1
解决办法
2387
查看次数

以编程方式设置android:windowIsTranslucent

按照本教程http://cases.azoft.com/android-tutorial-floating-activity/后,我能够创建一个浮动活动.

但是,要这样做,我必须添加以下内容styles.xml:

<item name="android:windowIsTranslucent">true</item>
Run Code Online (Sandbox Code Playgroud)

是否可以仅使用Android/Java代码获得相同的效果?(例如在Activity.onAttachedToWindow()...中)

在此先感谢您的帮助.

[编辑01] styles.xml不能改变(我不应该知道它里面有什么......).但出于测试目的,我使用的是默认值:

<resources>
    <style name="AppBaseTheme" parent="Theme.AppCompat.Light">
    </style>
    <style name="AppTheme" parent="AppBaseTheme">
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

[编辑02] Resources.Theme.applyStyle()似乎做我想要的(根据API描述:"将新属性值放入主题").所以我创建了以下内容custom_style.xml:

<resources>
    <style name="MyCustomStyle" >
        <item name="android:windowIsTranslucent">true</item>
    </style>
</resources>
Run Code Online (Sandbox Code Playgroud)

然后,onAttachedToWindow()我打电话给:

getTheme().applyStyle(R.style.MyCustomStyle, true);
Run Code Online (Sandbox Code Playgroud)

但它没有任何影响......

android android-layout android-theme android-windowmanager android-styles

3
推荐指数
1
解决办法
2万
查看次数

避免在自定义视图中进行布局更改动画,这些动画在WindowManager中更新

我有一个习惯RelativeLayout,我甚至已经设定setLayoutTransition(null);.我将此自定义视图添加到WindowManager中((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).updateViewLayout(this, layoutParams);

我在自定义视图中更改视图并更改了LayoutParamsfor WindowManager和之后的调用updateViewLayout...

我认为,LayoutParams对于WindowManager动画的变化,但我不确定...

如何禁用所有动画?

animation android view android-windowmanager

3
推荐指数
1
解决办法
1182
查看次数

以编程方式禁用多窗口功能

我正在尝试禁用android的多窗口功能。我已经阅读了android文档并知道resizeableActivity仅适用于android N(API级别24),但我想在较低级别的android API上禁用它。由于三星设备在其所有设备上均具有多窗口功能(大约)。所以我必须禁用它。

android multi-window android-windowmanager samsung-mobile-sdk android-window

3
推荐指数
1
解决办法
3737
查看次数

在android.view.Window类中明确addFlags和setFlags

我知道setFlags做的是用新的标志替换旧标志.并且addFlags会附加更多标志.我只是困惑为什么setFlags方法中的参数我通常看到的相同?例如:

getWindow().setFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION, WindowManager.LayoutParams.FLAG_TRANSLUCENT_NAVIGATION);
//or
getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN, WindowManager.LayoutParams.FLAG_FULLSCREEN);
Run Code Online (Sandbox Code Playgroud)

看了android.view.Window类后,我不清楚为什么他们必须做很多二元运算符(NOT,AND,OR).这样做的目的是什么?

public void setFlags(int flags, int mask) {
        final WindowManager.LayoutParams attrs = getAttributes();
        attrs.flags = (attrs.flags & ~mask) | (flags & mask);
        mForcedWindowFlags |= mask;
        dispatchWindowAttributesChanged(attrs);
    }
Run Code Online (Sandbox Code Playgroud)

还有一个问题,有什么区别

//argument is a flag
getWindow().addFlags(flag1);
Run Code Online (Sandbox Code Playgroud)

//argument is the result of OR operator of 2 identical flags
getWindow().addFlags(flag1 | flag1);
Run Code Online (Sandbox Code Playgroud)

//argument is the result of OR operator of 2 different flags
getWindow().addFlags(flag1 | flag 2);
Run Code Online (Sandbox Code Playgroud)

//argument is the result of AND operator of 2 …
Run Code Online (Sandbox Code Playgroud)

android android-windowmanager android-window

3
推荐指数
2
解决办法
3201
查看次数

我如何设置保持屏幕和全屏标志?

在我的应用程序全屏,我写这段代码:

  public void onCreate(Bundle savedInstanceState) {
         requestWindowFeature(Window.FEATURE_NO_TITLE);
         setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE);
           getWindow().setFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN,
                    WindowManager.LayoutParams.FLAG_FULLSCREEN); 
               super.onCreate(savedInstanceState); 
        setContentView(R.layout.main);
                       .
                       .
                       .
Run Code Online (Sandbox Code Playgroud)

并在我的应用程序中保持屏幕我在布局中编写此代码:

android:keepScreenOn="true" 
Run Code Online (Sandbox Code Playgroud)

虽然并非总是如此,但有时会像我这样错误:

java.lang.IllegalArgumentException: View not attached to window manager
at android.view.WindowManagerImpl.findViewLocked(WindowManagerImpl.java:381)
at android.view.WindowManagerImpl.removeView(WindowManagerImpl.java:226)
at android.view.Window$LocalWindowManager.removeView(Window.java:432)
at android.app.Dialog.dismissDialog(Dialog.java:278)
at android.app.Dialog.access$000(Dialog.java:71)
at android.app.Dialog$1.run(Dialog.java:111)
at android.app.Dialog.dismiss(Dialog.java:268)
at com.android.internal.app.AlertController$ButtonHandler.handleMessage(AlertController.java:166)
at android.os.Handler.dispatchMessage(Handler.java:99)
at android.os.Looper.loop(Looper.java:123)
at android.app.ActivityThread.main(ActivityThread.java:3691)
at java.lang.reflect.Method.invokeNative(Native Method)
at java.lang.reflect.Method.invoke(Method.java:507)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:847)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:605)
at dalvik.system.NativeStart.main(Native Method)
Run Code Online (Sandbox Code Playgroud)

我能做什么?我写真正的代码?谢谢...

android android-screen layoutparams android-windowmanager

2
推荐指数
1
解决办法
7261
查看次数

移动位于WindowManager中的ImageView不能正常工作

我正在尝试在屏幕上的所有内容上绘制一个图标(TOP MOST),类似于新的Facebook Messenger的聊天标题。

我已经创建了一个在后台工作的服务,并根据特定条件我的图标应出现在屏幕上(就像有人在Facebook上向您发送消息时,Messenger服务将挂接该消息并在屏幕上显示聊天头以进行通知关于新消息的内容)

我做了什么:

我已经创建了该服务,并授予它显示系统警报窗口的权限(因为该头部实际上是系统警报窗口)

[assembly: UsesPermission(Name = Android.Manifest.Permission.SystemAlertWindow)]
Run Code Online (Sandbox Code Playgroud)

我已经从ImageView继承了一个类(StickyHeadView),并使用以下方式实现了OnTouchListener侦听器:

class StickyHeadView : ImageView, Android.Views.View.IOnTouchListener
{
    private StickyHeadService OwnerService;

    public StickyHeadView(StickyHeadService ContextService, Context context)
        : base(context)
    {
        OwnerService = ContextService;
        SetOnTouchListener(this);
    }

    float TouchMoveX;
    float TouchMoveY;

    public bool OnTouch(View v, MotionEvent e)
    {
        var windowService = OwnerService.GetSystemService(Android.Content.Context.WindowService);
        var windowManager = windowService.JavaCast<Android.Views.IWindowManager>();

        switch (e.Action & e.ActionMasked)
        {
            case MotionEventActions.Move:
                TouchMoveX = (int)e.GetX();
                TouchMoveY = (int)e.GetY();
                OwnerService.LOParams.X = (int)(TouchMoveX);
                OwnerService.LOParams.Y = (int)(TouchMoveY);
                windowManager.UpdateViewLayout(this, OwnerService.LOParams);                    
                Log.Debug("Point : ", "X: " + Convert.ToString(OwnerService.LOParams.X) …
Run Code Online (Sandbox Code Playgroud)

ontouchlistener android-layout xamarin.android android-imageview android-windowmanager

2
推荐指数
1
解决办法
5535
查看次数

TranslateAnimation移动视图,但没有动画

我正在开发一个浮动,类似于facebook中的chatHead或OneNote中的浮动.

一旦我创建了它,我需要能够通过触摸图标来移动它,但当我停止拖动并释放手指时,我希望图标返回到屏幕的左边缘.

通过使用TranslateAnimation它可以工作,但没有动画.当我再次触摸图标时,图标出现在左边缘.

这是相关代码:

    trackerHead.setOnTouchListener(new View.OnTouchListener() {
        private int initialX;
        private int initialY;
        private float initialTouchX;
        private float initialTouchY;

        @Override public boolean onTouch(View v, MotionEvent event) {
            switch (event.getAction()) {
                case MotionEvent.ACTION_DOWN:
                    initialX = params.x;
                    initialY = params.y;
                    initialTouchX = event.getRawX();
                    initialTouchY = event.getRawY();
                    return true;
                case MotionEvent.ACTION_UP:
                    TranslateAnimation animation = new TranslateAnimation(
                            TranslateAnimation.ABSOLUTE, params.x,
                            TranslateAnimation.ABSOLUTE, initialX,
                            TranslateAnimation.ABSOLUTE, params.y,
                            TranslateAnimation.ABSOLUTE, params.y);
                    animation.setDuration(4000);
                    animation.setRepeatCount(1);
                    animation.setInterpolator(new AccelerateInterpolator());
                    trackerHead.startAnimation(animation);
                    params.x = initialX;
                    return true;
                case MotionEvent.ACTION_MOVE:
                    params.x = initialX + (int) (event.getRawX() - …
Run Code Online (Sandbox Code Playgroud)

android android-layout translate-animation android-windowmanager

2
推荐指数
1
解决办法
860
查看次数