ImageView是集成了View的组件,它的主要工作就是显示一些图片啊,虽然他的用法一句话概括了,但是我觉得学起来应该不会太简单,正所谓 短小而精悍么 :)

ImageView 派生了 ImageButton与QuickContactBadge两个类,ImageButton 与 Button的区别在于Button生成的按钮显示的文字,而ImageButton上面显示的是图片,当然我们也可以给Button设置他的background来添加一些图片;ImageButton是非常灵活的一个组件,因为他可以根据自定义的Drawable来改变按钮的一些动态样式;ImageButton同时也派生了一个ZoomButton得类,他可以“放大”、“缩小”跟他相似的还有一个叫做 ZoomControls的组件,只不过他同时提供了放大跟缩小的功能。

下面做一个例子,做一个简单的相册,上同时可以改变他的透明度

布局代码:

 <?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="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"> <Button
android:id="@+id/btnDown"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="降低透明底" /> <Button
android:id="@+id/btnUp"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="增加透明底" /> <Button
android:id="@+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="下一张图片" />
</LinearLayout> <LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"> <ImageView
android:id="@+id/image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitCenter"
android:src="@drawable/pic1" />
</LinearLayout> </LinearLayout>

java代码:

 package com.doliao.helloworld;

 import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.Button;
import android.widget.ImageView; public class MainActivity extends AppCompatActivity implements View.OnClickListener { ImageView imageView;
Button btnUp, btnDown, btnNext;
int arrayImageId[] = new int[]{R.drawable.pic1, R.drawable.pic2, R.drawable.pic3, R.drawable.pic4, R.drawable.pic5};
int currentIma = 1; //默认为第一张
int alpha = 255; //默认alpha值为255 @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_imageview); imageView = (ImageView) findViewById(R.id.image);
btnUp = (Button) findViewById(R.id.btnUp);
btnDown = (Button) findViewById(R.id.btnDown);
btnNext = (Button) findViewById(R.id.btnNext); btnUp.setOnClickListener(this);
btnDown.setOnClickListener(this);
btnNext.setOnClickListener(this); } @Override
public void onClick(View v) {
if (v.equals(btnNext)) {
imageView.setImageResource(arrayImageId[++currentIma % arrayImageId.length]);
}
if (v.equals(btnUp)) {
alpha += 20;
if (alpha >= 255) {
alpha = 255;
}
}
if (v.equals(btnDown)) {
alpha -= 20;
if (alpha <= 0) {
alpha = 0;
}
}
imageView.setImageAlpha(alpha);
}
}

下面是运行的图:

ImageButton 与Button 同为按钮组件,下面我们就来粗略的看一下他们的相同点和不同点

因而ImageButton 不支持setText,而Button支持。反之,ImageButton 支持setImageURI,而Button不支持

下图是Button ImageButton的图,可以看出 一个咋点击、弹起有个不同的形态,还是一个是一个形态,默认相同。

QuickContactBadge(关联联系人)

QuickContactBadge说白了也是图片按钮,但是他与图片按钮不同的就是,他可以指定联系人,当用户单击图片的时候就可以联系指定的人了。

下面简单的学习下例子,用教程来记忆这个关键词。

布局内的代码为:

 <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="match_parent"
android:layout_height="match_parent"> <QuickContactBadge
android:id="@+id/badge"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/pic1"
/>
</LinearLayout>

java内的代码:

 package com.doliao.helloworld;

 import android.app.Activity;
import android.os.Bundle;
import android.widget.QuickContactBadge; /**
* Created by Administrator on 2016/10/10 0010.
*/ public class ImageViewActivity extends Activity{ QuickContactBadge badge;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activyty_imageview2);
badge = (QuickContactBadge) findViewById(R.id.badge); badge.assignContactFromEmail("021-88888888",false);
}
}

运行的图片如下:

这写就是ImageView的一些常用的组件已经常用的方法,如果错误,请指出,谢谢!!

当然这不是ImageView下的所以的组件,还有其他的没有涉及到,等以后做东西遇到了在补充。

Android学习笔记⑥——UI组件的学习ImageView相关的更多相关文章

  1. Android学习笔记⑤——UI组件的学习TextView相关

    TextView是一个强大的视图组件,直接继承了View,同时也派生出了很多子类,TextView其作用说白了就是在布局中显示文本,有点像Swing编程中的JLabel标签,但是他比JLabel强大的 ...

  2. Android学习笔记⑧——UI组件的学习AdapterView相关2

    前面都是用ListView控件来配合Adapter做的一些实例,这次我们来见识一下GridView与Adapter之间的爱恨情仇.... GridView是用于在界面上按行.列分布的方式来显示多个的组 ...

  3. Android学习笔记⑦——UI组件的学习AdapterView相关1

    AdapterView是一个非常重要的组件之一,他非常灵活,所以得好好学...AdapterView本身是一个抽象类,派生出来的子类用法也十分相似,只是界面有一定的区别,因此本节把他们归为一类 Ada ...

  4. vue学习笔记(八)组件校验&通信

    前言 在上一章博客的内容中vue学习笔记(七)组件我们初步的认识了组件,并学会了如何定义局部组件和全局组件,上一篇内容仅仅只是对组件一个简单的入门,并没有深入的了解组件当中的其它机制,本篇博客将会带大 ...

  5. Vue学习笔记-Vue.js-2.X 学习(三)===>组件化高级

    (四) 组件化高级 1.插槽(slot)的基本使用 A:基本使用: <slot></slot> B:默认置:<slot><h1>中间可以放默认值< ...

  6. Vue学习笔记-Vue.js-2.X 学习(二)===>组件化开发

    ===重点重点开始 ========================== (三) 组件化开发 1.创建组件构造器: Vue.extends() 2.注册组件: Vue.component() 3.使用 ...

  7. Android开发 ---基本UI组件3:单选按钮、多选按钮、下拉列表、提交按钮、重置按钮、取消按钮

    Android开发 ---基本UI组件2 1.activity_main.xml 描述: 定义一个用户注册按钮 <?xml version="1.0" encoding=&q ...

  8. Vue学习笔记-Vue.js-2.X 学习(六)===>脚手架Vue-CLI(项目说明-Babel)

    五  Vue学习-vue-cli脚手架学习(创建只选一个选项:Babel) 1. 项目目录说明 node_modules : 包管理文件夹 public : 静态资源 src : 源代码 gitign ...

  9. Vue学习笔记-Vue.js-2.X 学习(四)===>脚手架Vue-CLI(基本工作和创建)

    (五) 脚手架Vue-CLI 一 Vue-CLI前提(nodejs和webpack) 二  Vue学习-nodejs按装配置,Node.js 就是运行在服务端的 JavaScript. 1. 去nod ...

随机推荐

  1. Spring REST实践之客户端和测试

    RestTemplate 可参考spring实战来写这部分. RestTemplate免于编写乏味的样板代码,RestTemplate定义了33个与REST资源交互的方法,涵盖了HTTP动作的各种形式 ...

  2. as [Frame]元标签

    [Frame(factoryClass="XXX_Class")] 利用Frame元标签.在主SWF类名上面添加 [Frame(factoryClass="加载类类名&q ...

  3. jquery validate使用

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  4. java/android线程池详解

    一,简述线程池: 线程池是如何工作的:一系列任务出现后,根据自己的线程池安排任务进行. 如图: 线程池的好处: 重用线程池中的线程,避免因为线程的创建和销毁所带来的性能开销. 能有效控制线程池的最大并 ...

  5. STM32 使用 printf 发送数据配置方法 -- 串口 UART, JTAG SWO, JLINK RTT

    STM32串口通信中使用printf发送数据配置方法(开发环境 Keil RVMDK) http://home.eeworld.com.cn/my/space-uid-338727-blogid-47 ...

  6. ARM Cortex-M instructions

    ARM Cortex-M instruction sets ARMCortex-M Thumb Thumb-2 Hardwaremultiply Hardwaredivide Saturatedmat ...

  7. Windows Server Backup 备份Hypver-V VM

    在Windows Server 2012中,可以通过Windows Server Backup备份Hypver-V VM.在还原时,将会还原到Hypver-V管理器中. 设置只保存2个备份副本,命令如 ...

  8. Educational Codeforces Round 7 C. Not Equal on a Segment 并查集

    C. Not Equal on a Segment 题目连接: http://www.codeforces.com/contest/622/problem/C Description You are ...

  9. 【ArcGIS 10.2新特性】Portal for ArcGIS新特性

    1.概述 经过各版本的积累和更新,Portal for ArcGIS在ArcGIS10.2中以正式产品的形态加入到了ArcGIS系列产品线中.它有3个主要定位:协同管理平台.在线制图平台以及内容管理平 ...

  10. 手把手教你使用 Imagepro plus - 宏操作【转】

    Imagepro plus操作5 – 提高测量效率的必须技术-宏操作(续) 星期三, 七月 7th, 2010 | 图像分析 | hbchendl | 浏览:897 请先参阅:Imagepro plu ...