1.在布局文件中添加一个图片,使用属性onClick添加点击事件,事件命名image_larger
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:scaleType="centerCrop"
android:onClick="image_larger"
android:src="@drawable/image" />
2.选中image_larger,Alt+回车键Create 'image larger(View)' in '**Activity',自动生成
ps:'**Activity'指的是图片所在布局文件对应的java页面
public void image_larger(View view) {
}
3.添加放大动画
public void image_larger(View view) {
// 创建一个补间动画,实现图片的放大效果
Animation animation = new ScaleAnimation(1, 2, 1, 2, Animation.RELATIVE_TO_SELF, 0.5f, Animation.RELATIVE_TO_SELF, 0.5f);
animation.setDuration(500); // 设置动画持续时间为500毫秒
animation.setFillAfter(true); // 动画结束后保持最后的状态
// 开始动画
view.startAnimation(animation);
}
810




被折叠的 条评论
为什么被折叠?



