Android UI之ImageView图片视图
来源:互联网 发布:vb手机版 编辑:程序博客网 时间:2024/06/05 02:29
ImageView是一个显示图片的组件,用一个例子介绍该组件的简单运用:
在样式文件中:
<?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" > <!-- android:src设置ImageView所显示的Drawable对象的ID --> <ImageView android:id="@+id/img1" android:layout_width="fill_parent" android:layout_height="300dp" android:background="#cccccc" android:src="@drawable/pig" /> <!--android:scaleType设置所显示的图片如何缩放或移动以适应ImageView的大小 其值在中文API上有详细的说明 --> <ImageView android:id="@+id/img2" android:layout_width="100dp" android:layout_height="100dp" android:background="#cccccc" android:scaleType="fitStart" android:layout_marginTop="20dp" /></LinearLayout>
该样式文件中有两个ImageView组件,第一个用来显示我们想要展示的图片,第二ImageView用来显示当点击图片上某一位置时在该组件上显示部分图片,代码实现该功能:
package cn.class3g.activity;import android.app.Activity;import android.graphics.Bitmap;import android.graphics.drawable.BitmapDrawable;import android.os.Bundle;import android.view.MotionEvent;import android.view.View;import android.view.View.OnTouchListener;import android.widget.ImageView;public class ImageViewDemo extends Activity implements OnTouchListener {ImageView imageView1, imageView2;protected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.setContentView(R.layout.imageview_layout);findViews();}private void findViews() {imageView1 = (ImageView) findViewById(R.id.img1);imageView2 = (ImageView) findViewById(R.id.img2);//为imageView添加触摸监听事件imageView1.setOnTouchListener(this);}public boolean onTouch(View v, MotionEvent event) {float scale = 412 / 320;//获取需要显示的图片的开始点int x = (int) (event.getX() * scale);int y = (int) (event.getY() * scale);//需要考虑边界问题int width = (int) (100 * scale);int height = (int) (100 * scale);//获取图片显示框中的位图BitmapDrawable bitmapDrawable = (BitmapDrawable) imageView1.getDrawable();//显示图片指定的区域imageView2.setImageBitmap(Bitmap.createBitmap(bitmapDrawable.getBitmap(),x,y, width, height));return false;}}
在模拟器上的效果为
:
- Android UI之ImageView图片视图
- Android UI之ImageView
- Android--UI之ImageView
- android 控件 图片视图(ImageView)
- Android UI 详解之ImageView
- Android学习:图片视图(ImageView)
- Android ImageView之切换图片
- android-UI组件实例大全(六)------ImageView图像视图
- Android第五天之ImageView图像视图
- Android之UI学习篇六:ImageView实现图片旋转和缩放
- Android之UI学习篇七:ImageView实现适屏和裁剪图片的功能
- 【Android 开发】:UI控件之显示图片控件 ImageView 的使用方法
- 【Android 开发】:UI控件之 ImageView 实现适屏和裁剪图片的功能
- 【Android 开发】:UI控件之 ImageView 实现图片旋转和缩放功能
- android困惑之UI---imageView实现对图片的选取,和裁剪功能。。。。
- Android进阶UI之ImageView设置长度高度为wrap_content时高度根据图片比例自适应
- Android之UI—ImageView scaleType属性
- Android UI 实战之圆形ImageView
- titanium mobile httpClient 在ios下的使用,后端应用服务器为nginx时注意事项
- IE/Firefox每次刷新时自动检查网页更新,无需手动清空缓存的设置方法
- HBase客户端程序
- 我的2011——一个通信设备商程序员的年度总结
- eclipse反编译工具安装
- Android UI之ImageView图片视图
- Hibernate懒加载解析
- UNICODE 基础知识
- Oracle group by 基本及的拓展 ROLLUP, CUBE, GROUPING 功能and GROUPING 集合
- ListBox的数据库绑定
- Gvim 字体大小设置
- AMR 文件解析及编解码流程
- Android之SurfaceView学习(一)
- MySQL数学函数