android动画,透明度渐变,图片移动

本文介绍了一个简单的Android应用程序,该程序实现了图片从透明到不透明的变化效果及文字从底部向上移动的动画效果。通过MainActivity类加载了两种类型的动画资源文件——alpha.xml用于调整图片的透明度,transplate.xml则负责实现文字的移动效果。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

效果是:图片由透明变为不透明,文字由下往上移动


MainActivity.java

package com.example.imagealpha_2;

import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.ImageView;
import android.widget.TextView;

public class MainActivity extends Activity {
	private ImageView imageView1,imageView2;
	private Animation animation,trans_animation;
	private TextView textView2,textView3;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		textView2 = (TextView) findViewById(R.id.textView2);
		textView3 = (TextView) findViewById(R.id.textView3);
		imageView1 = (ImageView) findViewById(R.id.imageView1);
//		imageView2 = (ImageView) findViewById(R.id.imageView2);
		
		animation = AnimationUtils.loadAnimation(MainActivity.this,
				R.anim.alpha);
		
		trans_animation = AnimationUtils.loadAnimation(MainActivity.this,
				R.anim.transplate);
		

		imageView1.startAnimation(animation);
	///	textView2.startAnimation(animation);
		textView2.startAnimation(trans_animation);
		textView3.startAnimation(trans_animation);
		

	}
}

layout.xml

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@android:color/holo_green_light"
    tools:context="${relativePackage}.${activityClass}" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="@string/hello_world" />

    <ImageView
        android:id="@+id/imageView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="99dp"
        android:src="@drawable/ic_launcher" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="124dp"
        android:text="悟空天气" />

    <TextView
        android:id="@+id/textView3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_below="@+id/textView2"
        android:layout_centerHorizontal="true"
        android:layout_marginTop="20dp"
        android:text="生活如虎添翼" />

</RelativeLayout>
alpha.xml

<?xml version="1.0" encoding="UTF-8"?>

<alpha 
    android:fromAlpha="0"
    android:toAlpha="1"  
    android:duration="1500"
    android:repeatCount="0"
    
    xmlns:android="http://schemas.android.com/apk/res/android"/>
transpalte.xml

<?xml version="1.0" encoding="utf-8"?>
<set xmlns:android="http://schemas.android.com/apk/res/android" android:interpolator="@android:anim/accelerate_interpolator">
    <translate 
        android:fromYDelta="100%p" 
        android:toYDelta="0%p"
        android:repeatMode="restart"
        android:interpolator="@android:anim/linear_interpolator"
        android:repeatCount="0"
        android:duration="1500" />
</set>




评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

二十六画生的博客

你的鼓励是我创作最大的动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值