猜猜红桃A在哪里(ImageView单击事件与透明度处理)
猜猜红桃A在哪里(ImageView单击事件与透明度处理)
新建一个继承Activity类的ImageViewGameActivity,并设置布局文件为:imageviewgame.xml。
首先定义布局文件。
<?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_parent" android:orientation="vertical" > <LinearLayout android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" > <ImageView android:id="@+id/imageviewgame_image01" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="1" android:src="@drawable/p_b1" /> <ImageView android:id="@+id/imageviewgame_image02" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="1" android:src="@drawable/p_b1" /> <ImageView android:id="@+id/imageviewgame_image03" android:layout_width="0dp" android:layout_height="wrap_content" android:layout_margin="10dp" android:layout_weight="1" android:src="@drawable/p_b1" /> </LinearLayout> <Button android:id="@+id/imageviewgame_btn" style="@android:style/Widget.Button.Inset" android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/sure" /> <TextView android:id="@+id/imageviewgame_tv" android:layout_width="fill_parent" android:layout_height="wrap_content" android:layout_marginTop="10dp" android:gravity="center_horizontal" android:text="@string/sure" android:textSize="20sp" /> </LinearLayout> |
效果:
而后在Activity获取这5个组件。
package lyx.feng.second; ...... public class ImageViewGame extends Activity implements OnClickListener { private ImageView image1 = null; private ImageView image2 = null; private ImageView image3 = null; private Button btn = null; private TextView tv = null; private List<Integer> cards = new ArrayList<Integer>(); @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); super.setContentView(R.layout.imageviewgame); initViews(); this.btn.setText("再来一次"); this.btn.setVisibility(View.GONE); } private List<Integer> getRandomCards(List<Integer> cards) { Collections.shuffle(cards); return cards; } private void setImages(List<Integer> cards) { this.image1.setImageResource(cards.get(0)); this.image2.setImageResource(cards.get(1)); this.image3.setImageResource(cards.get(2)); } private void initViews() { this.image1 = (ImageView) super .findViewById(R.id.imageviewgame_image01); this.image2 = (ImageView) super .findViewById(R.id.imageviewgame_image02); this.image3 = (ImageView) super .findViewById(R.id.imageviewgame_image03); this.btn = (Button) super.findViewById(R.id.imageviewgame_btn); this.tv = (TextView) super.findViewById(R.id.imageviewgame_tv); cards.add(R.drawable.p_h_2); cards.add(R.drawable.p_h_4); cards.add(R.drawable.p_h_7); this.image1.setOnClickListener(this); this.image2.setOnClickListener(this); this.image3.setOnClickListener(this); this.btn.setOnClickListener(this); this.tv.setVisibility(View.GONE); } @Override public void onClick(View v) { switch (v.getId()) { case R.id.imageviewgame_image01: showcard(); break; case R.id.imageviewgame_image02: showcard(); break; case R.id.imageviewgame_image03: showcard(); break; case R.id.imageviewgame_btn: this.image1.setImageResource(R.drawable.p_b1); this.image2.setImageResource(R.drawable.p_b1); this.image3.setImageResource(R.drawable.p_b1); this.image1.setClickable(true); this.image2.setClickable(true); this.image3.setClickable(true); this.btn.setVisibility(View.GONE); break; } } private void showcard() { setImages(getRandomCards(cards)); this.image1.setClickable(false); this.image2.setClickable(false); this.image3.setClickable(false); this.btn.setVisibility(View.VISIBLE); } } |
猜猜红桃A在哪里(ImageView单击事件与透明度处理)相关推荐
- android小程序--猜猜红桃A在哪儿
ImageView单击事件与透明度处理 范例说明 在还是黑白屏幕的时候手机游戏就有了,相信许多人都曾经有过利用手机里的小游戏来消磨时间吧!现在这个范例就简单的利用Android的ImageView对象 ...
- android猜猜红桃A游戏源码
一个简单的猜扑克游戏,很适合初学者,点击TextView扑克由反面变为正面,未点击的TextView有透明效果,点击再玩一次按钮,运行洗牌程序undefined 源码下载: http://code.6 ...
- android 翻牌动画,Android实现寻觅红桃A的翻牌游戏
有一种游戏,在我们还小的时候,会经常和小伙伴玩耍,拿出几张扑克牌,其中包含红桃A,游戏中有两种身份,洗牌者和猜测者,洗牌者通过洗牌打乱顺序,然后将所有纸牌背部朝向猜测者,由猜测者从中选择,如果抽出红桃 ...
- Android趣味课程:寻觅红桃A的翻牌游戏
有一种游戏,在我们还小的时候,会经常和小伙伴玩耍,拿出几张扑克牌,其中包含红桃A,游戏中有两种身份,洗牌者和猜测者,洗牌者通过洗牌打乱顺序,然后将所有纸牌背部朝向猜测者,由猜测者从中选择,如果抽出红桃 ...
- 小明左、右手中分别拿两张纸牌(比如:黑桃10和红桃8,数字10和8可通过键盘录入),要求编写代码交换小明手中的牌
package zuoye;import java.util.Scanner;public class Test7 {public static void main(String[] args) {/ ...
- java里如何表示黑桃方片_扑克红桃,方片,黑桃,梅花他们的顺序如何,代表什么意义呀?jac 爱问知识人...
一副扑克中的52张是正牌,表示一年中有52个星期:两张是副牌,大王表示太阳,小王代表月亮.由于一年有春.夏.秋.冬四个季度,所以又分别用黑桃.红桃.草花.方块4种花色表示.其中红色的红桃.方块表示白昼 ...
- 黑桃8形式的c语言编程,C语言的随机发牌程序(红桃、黑桃、梅花、方块)
做一个随机发牌的C语言程序,供大家学习,思考. 未做任何注释,有测试时候留下的一些输出语句,一遍方便测试. /* author:nunu qq:398269786 */ #include #inclu ...
- 2021-12-08:扑克牌中的红桃J和梅花Q找不到了,为了利用剩下的牌做游戏,小明设计了新的游戏规则: 1) A,2,3,4....10,J,Q,K分别对应1到13这些数字,大小王对应0; 2) 游
2021-12-08:扑克牌中的红桃J和梅花Q找不到了,为了利用剩下的牌做游戏,小明设计了新的游戏规则: A,2,3,4-10,J,Q,K分别对应1到13这些数字,大小王对应0; 游戏人数为2人,轮流 ...
- 52张扑克牌,红桃A和黑桃A同时被一个人拿到的概率
问题:52张扑克牌,红桃A和黑桃A同时被一个人拿到的概率 假设是N个人玩牌. 那么概率是 1/N. 为什么? 类似邮箱问题. 把N个人看做N个邮箱,红桃A放到每个邮箱的概率是 1/N 而黑桃A要想和红 ...
最新文章
- ARM CPU神经网络自动调度
- python基础练习(四)
- STM32F系列USART的IDLE中断要注意了
- 电脑不能打字_电脑拼音打字快速入门秘籍
- 图片延迟加载和滑动翻页
- 松鼠聚会(洛谷-P3964)
- 51单片机基本刷屏测试实验_51单片机实验
- spring.net 对象创建 几种情况
- python自动化测试——元素操作
- 【c语言复习笔记】初始c源程序及其数据类型
- 未解决:lrelease: could not exec ‘/usr/lib/qt5/bin/lrelease‘: No such file or directory
- Mysql基础之 ALTER命令
- 2020年实验室安全准入考试
- Python3 OpenCV 视频转字符动画
- 夜光带你走进Bootstrap(2)
- 天正菜单栏不见了怎么显示出来_天正建筑菜单栏不见了怎么调出来? _ 设计学院_设计软件教程自学网...
- c语言自动贩卖机找钱,c语言趣题之“找钱的方法数量 ”
- 毕业答辩PPT模板(10套免费+精选)
- html简单下拉菜单
- Direct I/O in DOSBOX for COMM serial communications with QBasic, TBasic or Pbasic
热门文章
- What can university bring to you?
- 揭万达快钱的互联网金融布局逻辑
- 数据结构猜字谜游戏(Java语言编写)
- encode和decode
- 一加9手机参数详细介绍,价格是多少
- java正则获取url参数_通过正则来获取URL的参数值
- 点阵图像与矢量图像的计算机记录原理,第二章像素地概念,分辨率地概念,点阵及矢量图象地特点。第四节:图像格式地选择.docx...
- 关于春节抢红包,rubby的用户体验
- 服务器主板选哪个型号好,服务器主板这两个哪个好?
- c语言编程表示%d,C语言编程中a=%d是什么意思啊