gpt4 book ai didi

android - 动画图像从下到上

转载 作者:数据小太阳 更新时间:2023-10-29 03:00:34 24 4
gpt4 key购买 nike

我知道我的问题会引起很多反对,但有人帮助我,我想向我的 imageview 添加动画,例如当我单击按钮从底部出现并向上移动时。喜欢这张照片

enter image description here

最佳答案

1. 创建定义动画move.xml

<?xml version="1.0" encoding="utf-8"?>
<set
xmlns:android="http://schemas.android.com/apk/res/android"
android:interpolator="@android:anim/linear_interpolator"
android:fillAfter="true">

<translate
android:fromYDelta="100%p"
android:toYDelta="0%p"
android:duration="1000" />
</set>

2. 创建 activity_animation.xml 以显示 ButtonImageView

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_animation"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="16dp">

<ImageView
android:id="@+id/icon"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
android:layout_centerHorizontal="true"
android:visibility="gone"/>

<Button
android:id="@+id/btnStart"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"/>

</RelativeLayout>

3.您的AnimationActivity应该是这样的:

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.view.animation.Animation;
import android.view.animation.AnimationUtils;
import android.widget.Button;
import android.widget.ImageView;
import android.widget.Toast;

public class AnimationActivity extends AppCompatActivity implements Animation.AnimationListener {

ImageView imageIcon;
Button btnStart;

// Animation
Animation animMoveToTop;

@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_animation);

imageIcon = (ImageView) findViewById(R.id.icon);
btnStart = (Button) findViewById(R.id.btnStart);

// load the animation
animMoveToTop = AnimationUtils.loadAnimation(getApplicationContext(), R.anim.move);

// set animation listener
animMoveToTop.setAnimationListener(this);

// button click event
btnStart.setOnClickListener(new View.OnClickListener() {

@Override
public void onClick(View v) {
imageIcon.setVisibility(View.VISIBLE);

// start the animation
imageIcon.startAnimation(animMoveToTop);
}
});
}

@Override
public void onAnimationEnd(Animation animation) {
// Take any action after completing the animation
// check for move animation
if (animation == animMoveToTop) {
Toast.makeText(getApplicationContext(), "Animation Stopped", Toast.LENGTH_SHORT).show();
}
}

@Override
public void onAnimationRepeat(Animation animation) {
// TODO Auto-generated method stub
}

@Override
public void onAnimationStart(Animation animation) {
// TODO Auto-generated method stub
}
}

输出:

enter image description here

希望对你有帮助~

关于android - 动画图像从下到上,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43550591/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com