Android游戏开发系统控件-ImageButton
来源:互联网 发布:独立网店源码 编辑:程序博客网 时间:2024/06/06 09:35
Android游戏开发系统控件-ImageButton
ImageButton与Button类似,区别在于ImageButton可以自定义一张图片作为一个按钮;
也正因为使用图片代替了按钮,所以ImageButton按下和抬起的样式效果需要自定义。
下面为学习ImageButton做的的实例:
创建ImageButton项目
模拟器运行效果截图:
按下按钮:
抬起按钮:
项目源码:
main.xml修改如下:
<?xml version="1.0" encoding="utf-8"?><LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="fill_parent" android:orientation="vertical" ><ImageButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:id="@+id/imageBtn" android:background="@drawable/nopress"/></LinearLayout>
ImageButtonActivity.java代码修改如下:
package com.ImageButton;import android.app.Activity;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.ImageButton;public class ImageButtonActivity extends Activity {private ImageButton Ibtn; /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); Ibtn = (ImageButton)findViewById(R.id.imageBtn); //为图片按钮添加触屏监听 Ibtn.setOnTouchListener(new OnTouchListener(){ public boolean onTouch(View v,MotionEvent event){ //当前用户为按下 if(event.getAction()==MotionEvent.ACTION_DOWN){ //设置图片按钮背景图 Ibtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.press)); //用户当前为抬起 }else if(event.getAction()==MotionEvent.ACTION_UP){ Ibtn.setBackgroundDrawable(getResources().getDrawable(R.drawable.nopress)); } return false; } }); }}
- Android游戏开发系统控件-ImageButton
- 3.Android 游戏开发常用的系统控件(Button、Layout、ImageButton)
- 【读书笔记《Android游戏编程之从零开始》】3.Android 游戏开发常用的系统控件(Button、Layout、ImageButton)
- Android 控件开发之ImageButton
- Android 控件开发之ImageButton
- Android游戏开发系统控件-Button
- Android游戏开发系统控件-EditText
- Android游戏开发系统控件-CheckBox
- Android游戏开发系统控件-ProgressBar
- Android游戏开发系统控件-ListView
- Android游戏开发系统控件-Dialog
- Android游戏开发系统控件-CheckBox
- android控件06 ImageButton
- Android控件ImageButton设置
- Android游戏开发系统控件-TabSpec与TabHost
- 7.Android 游戏开发常用的系统控件(Dialog)
- Android 控件之ImageButton、ImageView
- 【读书笔记《Android游戏编程之从零开始》】8.Android 游戏开发常用的系统控件(系统控件常见问题)
- dizhi
- VC LIST控件使用方法
- Ubuntu_添加一个与root相同权限的账号
- 代码质量之一-----代码是债务
- final,finally,finalize的区别
- Android游戏开发系统控件-ImageButton
- ViewPager实现左右两个屏幕的切换
- java split
- 随机生成十个不同的数
- 按钮控件Button和事件处理
- 给你的Kindle做一个RSS推送服务器
- 代码质量之二----善用代码静态分析工具
- C#----使用继承选择器创建继承窗体
- css重置样式表reset.css