本文介绍了android的图像视图比例动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

喜IM想知道如何缩放动画标志并移动其位置?

我有运行一些检查,然后当它完成我希望它缩小图像视图(标识)和移动它的if语句。

我的继承人布局

 < XML版本=1.0编码=UTF-8&GT?;
< RelativeLayout的的xmlns:机器人=htt​​p://schemas.android.com/apk/res/android
    机器人:layout_width =FILL_PARENT
    机器人:layout_height =FILL_PARENT
    机器人:方向=垂直
    机器人:背景=@可绘制/ bg_default>

    < ImageView的
        机器人:ID =@ + ID / su_logo
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentTop =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:layout_marginTop =34dp
        机器人:SRC =@可绘制/ su_logo
        机器人:contentDescription =@字符串/ cd_su_logo/>

    < ImageView的
        机器人:ID =@ + ID / su_shirts
        机器人:layout_width =WRAP_CONTENT
        机器人:layout_height =WRAP_CONTENT
        机器人:layout_alignParentBottom =真
        机器人:layout_centerHorizo​​ntal =真
        机器人:SRC =@可绘制/ su_shirts
        机器人:contentDescription =@字符串/ cd_su_shirts/>

< / RelativeLayout的>
 

我的继承人的java

 公共无效的onCreate(包savedInstanceState){
        super.onCreate(savedInstanceState);
        的setContentView(R.layout.layout_initialsetup);
        preChecks();
    }

公共无效preChecks(){
    //检查互联网连接

    //检查版本
    。字符串curVersion = getResources()的getString(R.string.app_version code);
    INT CURVER =的Integer.parseInt(curVersion);
    字符串LiveVersion =100;
    INT liveVer =的Integer.parseInt(LiveVersion);

    如果(CURVER< liveVer)Log.v(设置,有一个新版本);
    其他 {

        //规模的动画


    }




}
 

解决方案

您可以做到这一点的应用 ScaleAnimation TranslateAnimation 一起 AnimationSet

  //缩放
动画比例=新ScaleAnimation(fromXscale,toXscale,fromYscale,toYscale,Animation.RELATIVE_TO_SELF,0.5F,Animation.RELATIVE_TO_SELF,0.5F);
// 1秒持续时间
scale.setDuration(1000);
// 向上
动画效果基本show =新TranslateAnimation(fromX,TOX,弗罗米,玩具);
// 1秒持续时间
slideUp.setDuration(1000);
//动画将加入两个缩放和移动
AnimationSet动画集=新AnimationSet(真正的);
animSet.setFillEnabled(真正的);
animSet.addAnimation(规模);
animSet.addAnimation(效果基本show);
//启动动画组
logo.startAnimation(动画集);
 

hi im wanting to know how to scale animate a logo and move its position?

i have an if statement that runs some checks and then when its done i want it to scale down an image view (logo) and move it up.

heres my layout

<?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>

heres my 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


    }




}
解决方案

You can do that by applying ScaleAnimation and TranslateAnimation together in AnimationSet

// 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的图像视图比例动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-15 16:38