Android 查看其他布局后面的动画
我正在尝试将一个视图设置为另一个布局的动画,但我遇到了一个问题,因为我的视图位于布局后面。我试着把android:animateLayoutChanges=“true”,但没有成功。Android 查看其他布局后面的动画,android,android-animation,Android,Android Animation,我正在尝试将一个视图设置为另一个布局的动画,但我遇到了一个问题,因为我的视图位于布局后面。我试着把android:animateLayoutChanges=“true”,但没有成功。 我的代码: layout.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:
我的代码:
layout.xml
<RelativeLayout 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:animateLayoutChanges="true">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton" />
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:animateLayoutChanges="true"
android:background="#ffffff">
</LinearLayout>
</RelativeLayout>
项目将按照布局中的顺序绘制。对于布局,将首先绘制RadioButton,然后绘制LinearLayout。如果它们重叠,将在单选按钮上绘制线性布局 解决方案部分#1: 翻转RadioButton和LinearLayout的顺序,以便RadioButton始终最后绘制
<RelativeLayout
android:id="@+id/final_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="30dp"
android:background="#ffffff">
</RelativeLayout>
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton" />
在Android 5.1中测试并在应用程序启动时设置动画。我不确定您想要实现什么,但是如果您要将子视图移动到其容器外部,则需要禁用容器上的
clipChildren
和clipPadding
属性,以便看到子视图移动到父容器外部:
<RelativeLayout 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:clipChildren="false"
android:clipToPadding="false">
...
</RelativeLayout>
根据您回复的Karaokyo爵士的评论,我建议这是您想要的
RadioButton r1; // suppose you already referenced it
LinearLayout l1; // //
Animation anim = AnimationUtils.loadAnimation(getBaseContext(), R.anim.abc_slide_in_top);
// the R.anim. blah blah is the preferred animation you want
//when the time comes
if(r1.getParent() != null)
((ViewGroup)r1.getParent()).removeView(r1);
l1.addView(r1);
r1.startAnimation(anim);
// you can create an animation listener and add the view when the animation
//starts
关键是,它看起来会像你想要的那样 只需将所有xml布局元素属性设置为
android:clipChildren=“false”
&android:clipToPadding=“false”
。不要忘了做animatedView.bringToFront()
月前有同样的问题,努力工作几天后找到解决方案。找到我的名字 最简单的解决方案是尝试在xml中重新布局,以便在线性布局之后显示RadioButton 在开始动画之前,请调用bringchildTofront(您的RadioButton) 或 如果需要对图形顺序进行更多控制,请扩展RelativeLayout和override
protected int getChildDrawingOrder (int childCount, int i)
让我为您提供有关480X854像素mdpi屏幕的解决方案 场景1:您希望RadioButton以RelativeLayout作为父视图组跨越线性布局,而不是。您需要修复z顺序。按照以下布局进行更改。动画从点A(0,0)到点C(300300)从RelativeLayout开始
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="#ffffff">
</LinearLayout>
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="#ffffff">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
/>
</LinearLayout>
</RelativeLayout>
场景3:您希望RadioButton以LinearLayout作为父视图组跨LinearLayout设置动画,并且您的x或y值在任一方向上都超出了LinearLayout边界大小,例如x=800>480像素或y=1200>854像素
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
<!-- Allow all the children to go out of their parent boundaries -->
android:clipChildren="false"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
<!-- Allow all the children to go out of their parent boundaries -->
android:clipChildren="false"
<!-- Do not clip the children at the padding i.e. allow to children go
beyond the padding -->
android:clipToPadding="false"
android:background="#ffffff">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
/>
</LinearLayout>
</RelativeLayout>
android:clipChildren=“false”
android:clipToPadding=“false”
android:background=“#ffffff”>
我希望这有助于……快乐编码…线性布局在你的单选按钮上方。你说的“到另一个布局”是指你想让你的
单选按钮成为你的线性布局的孩子?是的,但别忘了我想要动画。所以,从一个布局转到另一个布局是很困难的
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="#ffffff">
</LinearLayout>
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
/>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
android:background="#ffffff">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
/>
</LinearLayout>
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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"
<!-- Allow all the children to go out of their parent boundaries -->
android:clipChildren="false"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_margin="20dp"
<!-- Allow all the children to go out of their parent boundaries -->
android:clipChildren="false"
<!-- Do not clip the children at the padding i.e. allow to children go
beyond the padding -->
android:clipToPadding="false"
android:background="#ffffff">
<RadioButton
android:id="@+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="New RadioButton"
/>
</LinearLayout>
</RelativeLayout>