【发布时间】: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>
这是一张图片:
蓝色背景属于content_main.xml的根LinearLayout,绿色背景属于包含content_main.xml的app_bar_main.xml
有谁知道为什么会发生这种情况以及如何解决?
【问题讨论】:
-
你找到解决这个问题的方法了吗?
标签: android android-layout android-animation