Issue
I have a smaller RelativeLayout and a custom layout MyView which are both contained in a parent RelativeLayout. MyView is larger in size than the child RelativeLayout but only appears during a certain event. I don't want it to take up layout space outside of this event. However, when I set it to View.VISIBLE, it causes the child RelativeLayout to jump downwards.
The parent RelativeLayout which contains these views is to be moved around the screen. The parent view is moved when the user touches the screen and a MotionEvent.MOVE is triggered. When you move the parent view to the edges of the screen and the MyView is View.INVISIBLE, the problem is that the MyView will still take up space and have collision with the screen borders, and it looks like there is an invisible wall between the child RelativeLayout and the edge of the screen. I want the effective size of the whole parent RelativeLayout view to be the same as the child RelativeLayout unless the MyView is visible.
Here is an image to help illustrate my problem.
<merge xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:custom="http://schemas.android.com/apk/res/com.example.myapp">
<com.example.MyView
android:id="@+id/my_view"
android:layout_width="175dp"
android:layout_height="175dp"
android:visibility="gone"
android:layout_centerInParent="true"
android:background="@color/red"/>
<RelativeLayout
android:id="@+id/rl"
android:layout_width="wrap_content" //Less than 175dp
android:layout_height="wrap_content" //Less than 175dp
android:orientation="vertical"
android:layout_centerInParent="true" >
</RelativeLayout>
</merge>
The merge view is then placed in a parent RelativeLayout which is defined in Java with these parameters.
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 = (int) (deviceRes.y * 0.1);
Solution
I solved the problem by pulling the MyView out of the merge view. I just made it so the MyView follows the movement of the merge view. So now the MyView and merge view are children of the screen manager and MyView is not a child of the merge view.
Answered By - ABC
Answer Checked By - David Goodson (JavaFixing Volunteer)