问题
hi,I was using WindowManager to display a floating window on the bottom of the screen, the floating window is about 120px high and the width is match_parent, so the outside of the floating window is touchable. In some cases, I need to update the window size to fullscreen to display some lists, at the same time, the original view should stay intact. I was using updateViewLayout method of WindowManager to update the layout of the floating window. The layout params of The small window is as follows:
windowParams.type = LayoutParams.TYPE_SYSTEM_ERROR;
windowParams.format = PixelFormat.RGBA_8888;
windowParams.gravity = Gravity.LEFT | Gravity.TOP;
windowParams.x = 0;
windowParams.y = 0;
windowParams.width = LayoutParams.MATCH_PARENT;
windowParams.height = 120;
windowParams.screenOrientation =
ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
Full screen layout params look the same, exception that the height param was set to LayoutParams.MATCH_PARENT:
windowParams.type = LayoutParams.TYPE_SYSTEM_ERROR;
windowParams.format = PixelFormat.RGBA_8888;
windowParams.gravity = Gravity.LEFT | Gravity.BOTTOM;
windowParams.x = 0;
windowParams.y = 0;
windowParams.width = LayoutParams.MATCH_PARENT;
windowParams.height = LayoutParams.MATCH_PARENT;
windowParams.screenOrientation = ActivityInfo.SCREEN_ORIENTATION_LANDSCAPE;
The problem is that when I call updateViewLayout to update the float window to full screen, the original small view jump to the top of the screen,which was not expected, and then the list shows and the small view back to the bottom, It look like the layout flashed. After seaching google, I did't found any answers, I wonder why did this happen, Was I using wrong LayoutPamams?
The layout file of the float window:
<?xml version="1.0" encoding="UTF-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/small_window_layout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#00000000"
android:baselineAligned="false"
android:keepScreenOn="true">
<RelativeLayout
android:id="@+id/webview_container"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@color/transparent" />
<RelativeLayout
android:id="@+id/r_dialog_view"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:padding="20dp">
<com.aispeech.dui.car.ui.InputField_
android:id="@+id/avartar_view"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toRightOf="@+id/avartar_view"
android:background="@drawable/asr"
android:gravity="center_vertical"
android:orientation="horizontal">
<com.aispeech.dui.car.ui.floatwindow.MarqueeTextView
android:id="@+id/t_content"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:ellipsize="marquee"
android:focusable="true"
android:marqueeRepeatLimit="marquee_forever"
android:singleLine="true"
android:textColor="#FFFFFFFF"
android:textSize="15sp" />
<ImageView
android:id="@+id/i_play_control"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:background="@mipmap/pause"
android:visibility="gone" />
</LinearLayout>
</RelativeLayout>
</RelativeLayout>
The RelativeLayout with id of "r_dialog_view" is the small view layout, before I set the view to full screen, I will set webview_container visible , which is for displaying full screen list.
There some View state screen capture:
bottom
jump to top
back to bottom
also see the video here: view behave weirdly
来源:https://stackoverflow.com/questions/47725813/view-behave-weirdly-when-updating-its-layoutparams-using-windowmanager