2016-09-13 93 views
0

我正在尝试在图像视图的动画中进行移动+淡入淡出。 我希望它从屏幕外部滑动到屏幕中间。 这里是我曾尝试:从外部移动图像视图

活动的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中工作。你能否以其他方式给我建议?

回答

3

删除您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

+0

感谢的人使用100,那效果更好 –