【发布时间】:2016-04-26 13:53:21
【问题描述】:
我有一个带有背景位图的 LinearLayout。我正在使用动画向此布局添加 2-3 张图像。问题是:每次我添加图像时,第一个图像动画从左上角开始,对于该动画之后的所有其他图像,它从中心开始工作得很好。我苦苦挣扎了好几天,为这个烦人的小问题找到解决方案。你有什么建议会导致这种情况吗?
这是我制作的 gif 中的问题:http://imgur.com/FCPgof1
我的动画:`
<scale
android:duration="750"
android:fillAfter="false"
android:fromXScale="0"
android:fromYScale="0.0"
android:interpolator="@android:anim/accelerate_decelerate_interpolator"
android:pivotX="50%"
android:pivotY="50%"
android:toXScale="1.0"
android:toYScale="1.0" />
`
我的布局:
<LinearLayout
android:id="@+id/layoutCompareUppoints"
android:layout_width="140dp"
android:layout_height="28dp"
android:background="@drawable/uppballsbgnew" >
</LinearLayout>
我的代码: `private void animUppointsBefore() {
if (k < Integer.valueOf(uppoints)) {
Animation a = AnimationUtils.loadAnimation(this,
R.anim.debug_grow_fast_animation);
ImageView upp = new ImageView(this);
upp.setImageResource(R.drawable.uppballlightnew);
upp.setAdjustViewBounds(true);
uppLayout.addView(upp);
upp.startAnimation(a);
a.setAnimationListener(new AnimationListener() {
@Override
public void onAnimationStart(Animation a) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationRepeat(Animation a) {
// TODO Auto-generated method stub
}
@Override
public void onAnimationEnd(Animation a) {
// TODO Auto-generated method stub
k++;
animUppointsBefore();
}
});
}
}`
【问题讨论】:
-
在 Q 中添加代码会有所帮助
-
我添加了我的动画代码。但是我想再说一遍,在我添加第一个图像后,我的代码对每个图像都运行良好。这让人很难理解
-
你试过RelativeLayout吗?我知道 LinearLayout 对免费图像操作不太友好
-
还没有,我希望我的图像显示在之前添加的图像旁边,这就是为什么使用线性布局
-
与 relativeLayout 的行为相同 :(
标签: android animation imageview pivot center