gpt4 book ai didi

Android:动画imageview

转载 作者:行者123 更新时间:2023-11-29 01:30:01 31 4
gpt4 key购买 nike

我正在使用我的闪屏。我想要一个动画 ImageView (从左到右)。我的代码确实有效,但滚动以黑色开始..

我想要的是从整个图像开始制作动画。

为了清楚理解,这是我的截图:

我的问题:

enter image description here

我的目标输出

enter image description here

public class splash extends Activity {

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_splash);

ImageView img_animation = (ImageView) findViewById(R.id.img_animation);
TranslateAnimation animation = new TranslateAnimation(0, 720, 239, 0);
animation.setDuration(10000);
animation.setFillEnabled(true);
img_animation.startAnimation(animation);
}
}

布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".Animation" >

<ImageView
android:id="@+id/img_animation"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:src="@drawable/splash_1"
android:scaleType="centerCrop" />

</RelativeLayout>

最佳答案

使用 FrameLayout 将 imageview 定位到 View 的开始并获取 imageview width = y 和 screen width = x 然后动画 y-x

您可以使用ObjectAnimator。这个 nineoldandroid 库与默认的 android Object animator 非常相似。

  AnimatorSet set = new AnimatorSet();

long scaleXAmount = y - x; (I mentioned it on above)
set.playTogether(
ObjectAnimator.ofFloat(view, "translationX", 0, scaleXAmount )
);
set.setDuration(800).start();

关于Android:动画imageview,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31722576/

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