【问题标题】:move imageView from outside screen从屏幕外移动 imageView
【发布时间】:2017-01-21 16:13:53
【问题描述】:

我正在尝试对 imageView 进行移动 + 淡入动画。 我希望它从屏幕外滑到屏幕中间。 这是我尝试过的:

活动 xml:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_alignParentTop="true"
    android:layout_alignParentRight="true">

    <ImageView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:src="@drawable/city"
        android:layout_alignParentBottom="true"
        android:layout_alignParentLeft="false"
        android:scaleType="fitEnd"
        android:id="@+id/cityImage" />

</RelativeLayout>

move.xml

<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">

<translate
    android:fromYDelta="-70%p"
    android:toYDelta="0%p"
    android:duration="1500" />
</set>

移动功能:

public void move(){
    ImageView image = (ImageView)findViewById(R.id.cityImage);
    Animation animation1 = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);
    image.startAnimation(animation1);
}

如您所见,我认为 javascript 方式是通过 -70%p 执行的,但它似乎在 android 中不起作用。你能建议我另一种方式吗?

【问题讨论】:

    标签: android imageview android-animation


    【解决方案1】:

    删除你的 move.xml

    然后加入这个

    public void move(){
        ImageView img_animation = (ImageView) findViewById(R.id.cityImage);
    
        TranslateAnimation animation = new TranslateAnimation(600.0f, 0.0f, 0.0f, 0.0f);         
        animation.setDuration(5000);      
    
        img_animation.startAnimation(animation);  
    }
    

    从右移到中间

    Omg 600 太多了,在 fromXdelta 中使用 100

    【讨论】:

    • 我怎样才能让它停留在结束位置?
    猜你喜欢
    • 2020-05-05
    • 1970-01-01
    • 1970-01-01
    • 2018-03-28
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多