Android 基础UI编程
专业相框设计
ImageView 的堆叠应用
① 新建工程
② 准备三张png 图片
left.png right.png photo.png
③ 修改main.xml 布局,添加UI 元素
 <?xml version="1.0" encoding="utf-8"?><AbsoluteLayoutandroid:id="@+id/widget34"android:layout_width="fill_parent"android:layout_height="fill_parent"xmlns:android="http://schemas.android.com/apk/res/android"><!--创建第一个ImageView (第二层图片)--><ImageViewandroid:id="@+id/myImageView1"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="0px"android:layout_y="36px"/><!--创建第二个ImageView (第一层图片)--><ImageViewandroid:id="@+id/myImageView2"android:layout_width="wrap_content"android:layout_height="wrap_content"android:layout_x="0px"android:layout_y="36px"/><!--创建第一个Button --><Buttonandroid:id="@+id/myButton1"android:layout_width="105px"android:layout_height="66px"android:text="pic1"android:layout_x="9px"android:layout_y="356px"/><!--创建第二个Button --><Buttonandroid:id="@+id/myButton2"android:layout_width="105px"android:layout_height="66px"android:text="pic2"android:layout_x="179px"android:layout_y="356px"/></AbsoluteLayout>

④ 修改mainActivity.java
package zyf.Ex_Ctrl_7;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.Button;import android.widget.ImageView;public class Ex_Ctrl_7 extends Activity {/** Called when the activity is first created. *//* 声明Button、ImageView 对象*/private ImageView mImageView01;private ImageView mImageView02;private Button mButton01;private Button mButton02;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);/* 取得Button、ImageView 对象*/mImageView01 = (ImageView) findViewById(R.id.myImageView1);mImageView02 = (ImageView) findViewById(R.id.myImageView2);mButton01 = (Button) findViewById(R.id.myButton1);mButton02 = (Button) findViewById(R.id.myButton2);/* 设置ImageView 背景图*/mImageView01.setImageDrawable(getResources().getDrawable(R.drawable.right));mImageView02.setImageDrawable(getResources().getDrawable(R.drawable.photo));/* 用OnClickListener 事件来启动*/mButton01.setOnClickListener(new Button.OnClickListener() {@Overridepublic void onClick(View v) {/* 当启动后, ImageView 立刻换背景图*/mImageView01.setImageDrawable(getResources().getDrawable(R.drawable.right));}});mButton02.setOnClickListener(new Button.OnClickListener() {@Overridepublic void onClick(View v) {mImageView01.setImageDrawable(getResources().getDrawable(R.drawable.left));}});}}

ImageButton 的堆叠应用
① 新建项目
② 准备三张png 图片
left.png right.png photo.png
③ 修改main.xml 布局,添加UI 元素
<?xml version="1.0" encoding="utf-8"?><AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"android:orientation="vertical"android:layout_width="fill_parent"android:layout_height="fill_parent"><ImageButtonandroid:id="@+id/myImageButton_Back"android:state_focused="true"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_x="0px"android:layout_y="36px"/><ImageButtonandroid:id="@+id/myImageButton_Photo"android:state_focused="true"android:layout_width="fill_parent"android:layout_height="wrap_content"android:layout_x="0px"android:layout_y="36px"/></AbsoluteLayout>

④ 修改mainActivity.java
设置成堆叠
package zyf.Ex_Ctrl_7_B;import android.app.Activity;import android.os.Bundle;import android.view.View;import android.widget.ImageButton;public class Ex_Ctrl_7_B extends Activity {/** Called when the activity is first created. *//*声明ImageButton*/private ImageButton back_Imagebutton,photo_Imagebutton;private boolean Tag=true;@Overridepublic void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);/*从XML中获取控件对象*/back_Imagebutton=(ImageButton)findViewById(R.id.myImageButton_Back );photo_Imagebutton=(ImageButton)findViewById(R.id.myImageButton_Photo );//设置默认的背景图片back_Imagebutton.setBackgroundResource(R.drawable.left);photo_Imagebutton.setBackgroundResource(R.drawable.photo);//给ImageButton设置事件监听器photo_Imagebutton.setOnClickListener(new ImageButton.OnClickListener(){@Overridepublic void onClick(View v) {// TODO Auto-generated method stubTag=!Tag;//更改背景图片if(Tag){back_Imagebutton.setBackgroundResource(R.drawable.right);}else{back_Imagebutton.setBackgroundResource(R.drawable.left);}}});}}

更多相关文章

  1. android -> 修改自动转为大写 的textAllCaps 属性
  2. android 中RecyclerView 嵌套了 GridView 的用法
  3. Android(安卓)App安装失败错误总结
  4. Android(安卓)ormlite 框架介绍
  5. android LinearLayout 动态添加子View
  6. 修改android项目sdk版本的方法
  7. 用Flex开发移动应用(1)---- 创建一个新的Mobile工程
  8. android dialog用法汇总
  9. Android应用程序中创建一个http服务器

随机推荐

  1. Android简单记录和恢复ListView滚动位置
  2. Android(安卓)init.rc文件解析过程详解(
  3. Android(安卓)studio 自动生成带系统权限
  4. Android(安卓)使用PDF.js浏览pdf的方法示
  5. AndroidManifest.xml中android:label标签
  6. Android(安卓)Jetpack 之 LifeCycle
  7. Android(安卓)获取判断是否有悬浮窗权限
  8. 【Android】Material Design 之二 Bottom
  9. android studio 导入Eclipse项目报错:thi
  10. android 开发生成csr,并把私钥和ca认证的c