android ImageView 缩放动画

标签 android animation

您好,我想知道如何缩放动画 Logo 并移动其位置?

我有一个运行一些检查的 if 语句,然后当它完成时我希望它缩小 ImageView ( Logo )并将其向上移动。

这是我的布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:orientation="vertical"
    android:background="@drawable/bg_default" >

    <ImageView
        android:id="@+id/su_logo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentTop="true"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="34dp"
        android:src="@drawable/su_logo" 
        android:contentDescription="@string/cd_su_logo"/>

    <ImageView
        android:id="@+id/su_shirts"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:src="@drawable/su_shirts"
        android:contentDescription="@string/cd_su_shirts" />

</RelativeLayout>

这是我的java

   public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_initialsetup);
        preChecks();
    }

public void preChecks(){
    //check for internet connection

    //check version
    String curVersion = getResources().getString(R.string.app_versionCode);
    int curVer = Integer.parseInt(curVersion);  
    String LiveVersion = "100";
    int liveVer = Integer.parseInt(LiveVersion);

    if(curVer < liveVer) Log.v("setup", "There is a new version");  
    else { 

        //scale animation


    }   




} 

最佳答案

您可以通过在 AnimationSet 中同时应用 ScaleAnimationTranslateAnimation 来做到这一点

// Scaling
Animation scale = new ScaleAnimation(fromXscale, toXscale, fromYscale, toYscale, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
// 1 second duration
scale.setDuration(1000);
// Moving up
Animation slideUp = new TranslateAnimation(fromX, toX, fromY, toY);
// 1 second duration
slideUp.setDuration(1000);
// Animation set to join both scaling and moving
AnimationSet animSet = new AnimationSet(true);
animSet.setFillEnabled(true);
animSet.addAnimation(scale);
animSet.addAnimation(slideUp);
// Launching animation set
logo.startAnimation(animSet);

关于android ImageView 缩放动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11422421/

相关文章:

ios - MKMapView 淡入但不会通过动画淡出

javascript - 矩形正在翻转和旋转。我只是想让它绕一圈旋转

javascript - 使动画变慢(jQuery)

javascript - 停止动画停止工作,jQuery/悬停

java - android DialogFragment mDialog 为空导致异常

系统应用程序的 Android 运行时权限

android - 如何正确取消实时多人比赛?

android - fragment 崩溃 : java. lang.IllegalArgumentException:找不到 View

java - 三重 DES 加密字符串生成 "\n"

ios - View 未显示?