从屏幕外移动imageView [英] move imageView from outside screen

查看:197
本文介绍了从屏幕外移动imageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am trying to do a move + fade in animations to an imageView. I want it to slide from outside the screen to the middle of the screen. here's what I have tried :

活动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);
}

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

as you can see I thought the javascript way by doing -70%p but it doesnt seem to work in android. can you please suggest me an other way?

推荐答案

删除move.xml

Remove your 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

Omg 600 is too much, just use 100 in fromXdelta

这篇关于从屏幕外移动imageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆