Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to move a view via windowManager.UpdateViewLayout without any animation?

When i do :

    LayoutParams lp = getLayoutParams(view);
    lp.x = absoluteX;
    lp.y = absoluteY;
    this.mWindowManager.updateViewLayout(view, lp);

Then i have one linear animation from the position where the view is to the new position absoluteX/absoluteY. how to move the view without any animation ?

I try to set lp.windowAnimations = 0 but it's change nothing :( any idea how i can do ?

If it's not possible to avoid the animation, is their any way to know the actual position of the view? maybe i can make it invisible still the real position is not absoluteX/absoluteY

NOTE:

looking the source code of android, i saw in the file WindowManager.java this entry :

     /**
     * Never animate position changes of the window.
     *
     * {@hide} */
    public static final int PRIVATE_FLAG_NO_MOVE_ANIMATION = 0x00000040;

    /**
     * Control flags that are private to the platform.
     * @hide
     */
    public int privateFlags;

it's look like to be what i need, but i don't know how to access and set such flag :( any idea ?

like image 722
zeus Avatar asked Nov 08 '22 08:11

zeus


2 Answers

try to disable the layout animation:

android:animateLayoutChanges="false"
like image 140
Metwalli Avatar answered Nov 15 '22 04:11

Metwalli


val lp = WindowManager.LayoutParams(
    width, 
    height, 
    this.windowManagerType(),
    WindowManager.LayoutParams.FLAG_NOT_FOCUSABLE
    or WindowManager.LayoutParams.FLAG_WATCH_OUTSIDE_TOUCH
    or WindowManager.LayoutParams.FLAG_KEEP_SCREEN_ON
    or WindowManager.LayoutParams.FLAG_LAYOUT_IN_SCREEN
    or WindowManager.LayoutParams.FLAG_LAYOUT_NO_LIMITS,
    PixelFormat.TRANSPARENT
)

val className = "android.view.WindowManager\$LayoutParams"
try {
    val layoutParamsClass = Class.forName(className)
    val privateFlags = layoutParamsClass.getField("privateFlags")
    val noAnim = layoutParamsClass.getField("PRIVATE_FLAG_NO_MOVE_ANIMATION")

    var privateFlagsValue = privateFlags.getInt(lp)
    val noAnimFlag = noAnim.getInt(lp)
    privateFlagsValue = privateFlagsValue or noAnimFlag
    privateFlags.setInt(lp, privateFlagsValue)
} catch (e: Exception) {
    Log.e("EXCEPT", "EXCEPTION: ${e.localizedMessage}")
}
like image 33
Данияр Габбасов Avatar answered Nov 15 '22 05:11

Данияр Габбасов