【问题标题】:Content gets pushed under toolbar when using animateLayoutChanges="true"使用 animateLayoutChanges="true" 时,内容被推送到工具栏下
【发布时间】:2015-12-17 21:24:42
【问题描述】:

我使用 Navigation Drawer Activity 创建了一个新的 Android Studio 项目。

然后我在 content_main.xml 的 LinearLayout 中添加了一个简单的 TextView。 在此 LinearLayout 中(也使用标准的 RelativeLayout 进行了尝试),我添加了 android:animateLayoutChanges="true" 参数。

如果我现在在 GONE 和 VISIBLE 之间切换 TextView 的可见性,content_main.xml 的整个根 LinearLayout 会被向上推并隐藏在工具栏下。

这是我的 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>

这是一张图片:

picture

蓝色背景属于content_main.xml的根LinearLayout,绿色背景属于包含content_main.xml的app_bar_main.xml

有谁知道为什么会发生这种情况以及如何解决?

【问题讨论】:

  • 你找到解决这个问题的方法了吗?

标签: android android-layout android-animation


【解决方案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>

这是一个丑陋的修复,但它现在有效。

如果出现其他问题,您可以通过将其添加为根布局的直接子级来解决它:

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

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

【讨论】:

    猜你喜欢
    • 2021-09-13
    • 1970-01-01
    • 1970-01-01
    • 2019-01-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多