簡體   English   中英

如何放大和縮小動畫到android中的圖像

[英]how to zoom in and zoom out animation to the image in android

我正在 android 中開發一個帶有縮放動畫的應用程序。 就像在按鈕 onclick 事件中轉到下一個活動一樣,在該活動中,我有一個圖像,該圖像應該用動畫放大。 如果有人遇到這個幫助我。

在您的下一個 Activity onCreate()方法中使用此代碼

ImageView imageView = (ImageView)findViewById(R.id.imageView);
        
Animation animZoomin = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.zoom_in);
        
imageView.startAnimation(animZoomin);

創建一個定義要執行的動畫類型的 xml 文件。 該文件應位於res 目錄下的 anim 文件夾下(res ⇒ anim ⇒ zoom_in.xml) 如果您的 res 目錄中沒有 anim 文件夾,請創建一個。

將以下代碼放在zoom_in.xml文件中

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android"
    android:fillAfter="true" >
 
    <scale
        android:duration="1000"
        android:fromXScale="1"
        android:fromYScale="1"
        android:pivotX="50%"
        android:pivotY="50%"
        android:toXScale="3"
        android:toYScale="3"/>
</set>

StackOverFlow 上似乎有一些類似的主題:

在android中放大和縮小動畫

放大動畫

這是 developer.android.com 上的一篇文章:

http://developer.android.com/training/animation/zoom.html

希望有幫助。 :]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM