[Bug]: Window position jumps when window content size changes on Android 13-14
Framework Version [Required]
Source code of v12.0
Issue Description [Required]
Hello! I encountered window position jumps when changing the content size. This only applies to the global floating window. I can reproduce this bug on my physical device with API level 33 and in the Android Studio emulator with API 33 and 34. It’s not reproducible on API levels 32 or 35-36 in the emulator.
Steps to Reproduce [Required]
For tests I used sources of v12.0 and changed EasyWindow initialization in method showGlobalWindow() like this:
EasyWindow.with(application)
.setContentView(R.layout.expanding_layout)
.setGravity(Gravity.END | Gravity.BOTTOM)
.setYOffset(200)
// 设置指定的拖拽规则
.setWindowDraggableRule(springBackWindowDraggableRule)
.setOnClickListenerByView(R.id.root_container, new OnWindowViewClickListener<LinearLayout>() {
@Override
public void onClick(@NonNull EasyWindow<?> easyWindow, @NonNull LinearLayout view) {
ImageView firstView = view.findViewById(R.id.first_part);
if (firstView.getVisibility() == View.VISIBLE) {
firstView.setVisibility(View.GONE);
} else {
firstView.setVisibility(View.VISIBLE);
}
}
})
.setOnWindowLifecycleCallback(new OnWindowLifecycleCallback() {
@Override
public void onWindowCancel(@NonNull EasyWindow<?> easyWindow) {
// 在窗口消失的时候回收资源,避免 LeakCanary 一直报内存泄漏,关于这点框架文档有介绍,详情请看文档
easyWindow.recycle();
}
})
.show();
Also added 1 layout file (expanding_layout.xml):
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/root_container"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="@+id/first_part"
android:layout_width="100dp"
android:layout_height="100dp"
android:visibility="gone"
android:src="#FFAA00" />
<ImageView
android:id="@+id/second_part"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="#FFAA00AA" />
</LinearLayout>
Steps to reproduce:
- Modify sources as above
- Show global floating window
- Move window to new position and click to change window size (repeat if needed)
Is the Issue Reproducible? [Required]
Yes
Project targetSdkVersion [Required]
33
Device Information [Required]
Asus ZB602KL and last Android Studio emulator
Android Version [Required]
13 and 14
Issue Source Channel [Required]
Encountered by myself
Is it specific to certain device models? [Required]
No
Does the latest version of the framework have this issue? [Required]
Yes
Is the issue mentioned in the framework documentation? [Required]
No
Did you consult the framework documentation but couldn't find a solution? [Required]
Yes
Has a similar issue been reported in the issue list? [Required]
No
Have you searched the issue list but couldn't find a solution? [Required]
Yes
Can the issue be reproduced with a demo project? [Required]
Yes
Provide Error Stack Trace
Provide Screenshots or Videos
https://github.com/user-attachments/assets/1e623f35-fe05-471f-8cd1-c5f37bf8501c
Provide a Solution
No response
Hello, I have investigated the problem. It's a system issue and there is no good solution for it at present.
Did you find any confirmation or relation indicating that it is a system bug itself? Unfortunately, I haven’t found any issues related to this on issuetracker.google.com. And I don’t fully understand the implementation to pinpoint where the error occurs, which makes it difficult for me to create a minimal reproducible sample to file an issue report. There are apps (e.g., Shazam) that don’t have this issue with floating windows. This suggests that the problem may depend on the implementation or at least has a possible workaround.
You can try using WindowManager to see if there is the same problem?
If you find that there is no problem using WindowManager but the framework has issues, it proves that my conclusion is wrong. Please let me know and I will handle the problem properly.
Unfortunately, I’m not very experienced with Android, and I don’t know how to properly use system APIs. I can certainly try, but I’ll likely achieve worse results than you, since you’ve been doing this library for years. If your expertise suggests there’s no good solution, then that’s fine. Nevertheless, thank you for your hard work.