Android 当位置因高度更改而更改时,为RelativeLayout子对象设置动画
我在我的Android应用程序中有这样的布局(我将它与主菜单屏幕一起用作启动屏幕) 这是XMLAndroid 当位置因高度更改而更改时,为RelativeLayout子对象设置动画,android,android-layout,Android,Android Layout,我在我的Android应用程序中有这样的布局(我将它与主菜单屏幕一起用作启动屏幕) 这是XML <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" androi
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
tools:context="com.izzivizzi.avant2go.ACMainActivity"
android:background="@mipmap/wallpaper"
android:orientation="vertical"
android:animateLayoutChanges="true">
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1">
...................
</RelativeLayout>
<LinearLayout
android:id="@+id/mainMenuButtons"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="2"
android:layout_marginTop="@dimen/margin_middle"
android:orientation="vertical"
android:visibility="gone">
...................
</LinearLayout>
</LinearLayout>
...................
...................
它应该做什么
活动开始时,仅用权重1显示相对值,这意味着儿童在屏幕中间显示(这是一个文本视图和一些图像,但我认为这里是多余的信息)。 几秒钟后,LinearLayout的可见性设置为VISIBLE,它的权重为2,这意味着它将向上推顶部RelativeLayout
现在,由于主LinearLayout的animateLayoutChanges设置为true,我希望RelativeLayout的子对象将设置动画到其新位置(朝向屏幕顶部),并且新的LinearLayout元素将缓慢出现 线性布局确实会慢慢出现,但是RelativeLayout的孩子们只是眨眼,因为RelativeLayout的位置实际上没有改变,只是改变了它的高度 问题 现在,由于RelativeLayout的孩子只是眨眼而不是动画,我需要找到一种方法,在线性布局缓慢出现时,将其动画化到顶部我将非常感谢能解决这个问题。谢谢!与其切换可见性,为什么不在代码中添加线性布局 您可以将其保留在布局文件中,只需获取对它的引用:然后在运行几秒钟后将其删除,然后将其添加回(确保使用适当的布局参数并设置权重)