gpt4 book ai didi

Android:动画被父 View 剪辑

转载 作者:IT老高 更新时间:2023-10-28 22:19:24 28 4
gpt4 key购买 nike

我目前有一个 ImageView,我正在向其应用缩放动画。此 View 位于相对布局内,其中 layout_height 和 layout_width 设置为 wrap_content。问题是当动画开始时,它使 ImageView 大于其父布局,然后图像被切断。反正有这个吗?

这是一个工作示例:

xml 文件 -

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent">
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dip"
android:layout_gravity="center_horizontal">
<ImageView
android:id="@+id/imgO"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/circle"/>
</RelativeLayout>
</LinearLayout>

java 文件 -

ImageView imgO;

ScaleAnimation makeSmaller;
ScaleAnimation makeBigger;

@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.titlescreen);

//Animation
imgO = (ImageView)findViewById(R.id.imgO);

makeSmaller = new ScaleAnimation((float)10.0, (float)1.0, (float)10.0, (float)1.0, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);
makeSmaller.setAnimationListener(new MyAnimationListener());
makeSmaller.setFillAfter(true);
makeSmaller.setDuration(500);
makeBigger = new ScaleAnimation((float)1.0, (float)10.0, (float)1.0, (float)10.0, Animation.RELATIVE_TO_SELF, (float)0.5, Animation.RELATIVE_TO_SELF, (float)0.5);
makeBigger.setAnimationListener(new MyAnimationListener());
makeBigger.setFillAfter(true);
makeBigger.setDuration(750);
imgO.startAnimation(makeBigger);
}

class MyAnimationListener implements AnimationListener {

public void onAnimationEnd(Animation animation) {

ScaleAnimation sa = (ScaleAnimation)animation;

if (sa.equals(makeSmaller))
imgO.startAnimation(makeBigger);
else
imgO.startAnimation(makeSmaller);
}

public void onAnimationRepeat(Animation animation) {
}

public void onAnimationStart(Animation animation) {
}

}

谢谢。

最佳答案

对你来说有点晚了,但对于每个寻找答案的人来说:你可以在封闭的 ViewGroups 上调用 setClipChildren(false) (如 RelativeLayoutLinearLayout )。

关于Android:动画被父 View 剪辑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6424178/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com