2023年7月7日发(作者:)
AndroidAnimation之TranslateAnimation(平移动画)TranslateAnimation(平移动画)的意思⽆⾮就是⼀张图⽚或其他从⼀个位置到达另外⼀个位置。直接代码分析,相关重要属性参数解释都在代码中。
1、⾸先编写⽂件。 xmlns:tools="/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" android:paddingBottom="@dimen/activity_vertical_margin" tools:context=".MainActivity"> android:id="@+id/image" android:text="@string/hello_world" android:layout_width="wrap_content" android:layout_height="wrap_content" android:src="@drawable/car_one1"/>
2、接下来编写⽂件。package project;
import patActivity;
import ;
import ;
import ion;
import ionSet;
import ateAnimation;
import iew;
public class MainActivity extends AppCompatActivity {
private ImageView image;
@Override
protected void onCreate(Bundle savedInstanceState) {
te(savedInstanceState);
setContentView();
image =(ImageView)findViewById();
lickListener(new OnClickListenerImpl());
}
private class OnClickListenerImpl implements kListener {
@Override
public void onClick(View v) {
/*
AnimationSet相当于⼀个动画的集合,true表⽰使⽤Animation的interpolator
false则是使⽤⾃⼰的。
Interpolator 被⽤来修饰动画效果,定义动画的变化率,可以使存在的动画效果
accelerated(加速),decelerated(减速),repeated(重复),bounced(弹跳)等。
*/
AnimationSet animationSet = new AnimationSet(true);
/*
Animation还有⼏个⽅法
setFillAfter(boolean fillAfter)
如果fillAfter的值为真的话,动画结束后,控件停留在执⾏后的状态
setFillBefore(boolean fillBefore)
如果fillBefore的值为真的话,动画结束后,控件停留在动画开始的状态
setStartOffset(long startOffset)
设置动画控件执⾏动画之前等待的时间
setRepeatCount(int repeatCount)
设置动画重复执⾏的次数
*/
TranslateAnimation translateAnimation = new TranslateAnimation(
//X轴初始位置
VE_TO_SELF, 0.0f,
//X轴移动的结束位置
VE_TO_SELF,0.5f,
//y轴开始位置
VE_TO_SELF,0.0f,
//y轴移动后的结束位置 VE_TO_SELF,1.5f);
//3秒完成动画
ation(2000);
//如果fillAfter的值为真的话,动画结束后,控件停留在执⾏后的状态
lAfter(true);
//将AlphaAnimation这个已经设置好的动画添加到 AnimationSet中
mation(translateAnimation);
//启动动画
nimation(animationSet);
}
}
}
以上就是本⽂的全部内容,希望对⼤家的学习有所帮助,也希望⼤家多多⽀持。
发布者:admin,转转请注明出处:http://www.yc00.com/xiaochengxu/1688676280a161724.html
评论列表(0条)