以编程方式显示 ImageView [英] Show ImageView programmatically

查看:31
本文介绍了以编程方式显示 ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当用户单击按钮时,如何使 ImageView 出现在屏幕中间?我已将图像放在 res/drawable-folder 中.

How can I make an ImageView appear in the middle of the screen when the user clicks a button? I have placed the image in the res/drawable-folder.

我一直在尝试使用下面的代码,但我不知道如何使 ImageView 出现:

I've been trying with the code below but I don't know how to make the ImageView appear:

 View v = new ImageView(getBaseContext());
 ImageView image; 
 image = new ImageView(v.getContext()); 
 image.setImageDrawable(v.getResources().getDrawable(R.drawable.gameover));

谢谢!

推荐答案

  • 创建ImageView
  • 在按钮中使用 OnClickListener
  • 添加ImageView 到布局或设置可见性ImageView 到 VISIBLE
    • Create the ImageView
    • Use an OnClickListener in the button
    • Add the ImageView to the layout or set the visibility of the ImageView to VISIBLE
    • 这篇关于以编程方式显示 ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆