Content is pushed under the toolbar when using animateLayoutChanges = "true"

I created a new Android Studio project with navigation box activity.

Then I added a simple TextView inside LinearLayout to content_main.xml. For this LinearLayout (also tried this with the standard RelativeLayout) I added a    android:animateLayoutChanges="true" Parameter.

If now I switch the TextView visibility between GONE and VISIBLE, the entire LinearLayout root of content_main.xml will be pushed and hidden under the toolbar.

here is my content_main.xml

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
tools:showIn="@layout/app_bar_main"
tools:context=".MainActivity"
android:background="#84d8ff">

<TextView android:text="Hello World!" android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/textView2" />

<Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:text="New Button"
    android:id="@+id/button"
    android:layout_below="@+id/textView2"
    android:layout_centerHorizontal="true"
    android:layout_marginTop="207dp" />

<LinearLayout
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="#ff0004"
    android:animateLayoutChanges="true">

    <TextView android:text="Lorem Ipsum..."
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/test_item"
        android:layout_marginTop="29dp" />
</LinearLayout>

Here is the image:

picture

The blue background belongs to the root LinearLayout content_main.xml, the green background belongs to app_bar_main.xml, which includes content_main.xml

Does anyone know why this is happening and how to solve it?

+4
1

. , app_bar_main.xml

:

<include layout="@layout/content_main" />

:

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal"
    android:gravity="bottom">

    <include layout="@layout/content_main" />

</LinearLayout>

, .

, , rootlayout:

<android.support.v4.widget.Space
    android:layout_width="match_parent"
    android:layout_height="?attr/actionBarSize">

</android.support.v4.widget.Space>
0

Source: https://habr.com/ru/post/1620640/


All Articles