View(视图)——图片视图

一.图片视图

1.关键词:ImageView;

2.src  图片来源

3.alpha 透明度

1>.设置值为 0~1;

2>.<=0,全透明

3>.>=1,不透明

二.scaleType 显示类型

1.center

以原图的几何中心点和ImagView的几何中心点为基准,按图片的原来size居中显示,不缩放,当图片长/宽超过View的长/宽,则截取图片的居中部分显示ImageView的size.当图片小于View 的长宽时,只显示图片的size,不剪裁。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp2.TestActivity1"
11     android:orientation="vertical">
12
13     <ImageView
14         android:layout_width="110dp"
15         android:layout_height="110dp"
16         android:src="@drawable/yuantu"
17         android:alpha="1"
18         android:background="#f00" />
19     <ImageView
20         android:layout_width="110dp"
21         android:layout_height="110dp"
22         android:src="@drawable/yuantu"
23         android:alpha="1"
24         android:background="#f00"
25         android:scaleType="center"/>
26 <LinearLayout>

center

2.centerCrop

以原图的几何中心点和ImagView的几何中心点为基准,按比例扩大(图片小于View的宽时)图片的size居中显示,使得图片长 (宽)等于或大于View的长(宽),并按View的大小截取图片。当原图的size大于ImageView时,按比例缩小图片,使得长宽中有一向等于ImageView,另一向大于ImageView。实际上,使得原图的size大于等于ImageView。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp2.TestActivity1"
11     android:orientation="vertical">
12
13      <ImageView
14         android:layout_width="110dp"
15         android:layout_height="110dp"
16         android:src="@drawable/yuantu"
17         android:alpha="1"
18         android:background="#f00" />
19
20       <ImageView
21         android:layout_width="110dp"
22         android:layout_height="110dp"
23         android:src="@drawable/yuantu"
24         android:alpha="1"
25         android:background="#f00"
26         android:scaleType="centerCrop"/>
27
28 <LinearLayout >

centerCrop

3.centerInside

以原图的几何中心点和ImagView的几何中心点为基准,将图片的内容完整居中显示,通过按比例缩小原来的size使得图片长(宽)等于或小于ImageView的长(宽)。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp2.TestActivity1"
11     android:orientation="vertical">
12
13      <ImageView
14         android:layout_width="110dp"
15         android:layout_height="110dp"
16         android:src="@drawable/yuantu"
17         android:alpha="1"
18         android:background="#f00" />
19
20        <ImageView
21             android:layout_width="110dp"
22             android:layout_height="110dp"
23             android:src="@drawable/yuantu"
24             android:alpha="1"
25             android:background="#f00"
26             android:scaleType="centerInside"/>
27
28 <LinearLayout >

centerInside

4.matrix

是保持原图大小、从左上角的点开始,以矩阵形式绘图。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp2.TestActivity1"
11     android:orientation="vertical">
12
13     <ImageView
14         android:layout_width="110dp"
15         android:layout_height="110dp"
16         android:src="@drawable/yuantu"
17         android:alpha="1"
18         android:background="#f00" />
19
20      <ImageView
21         android:layout_width="110dp"
22         android:layout_height="110dp"
23         android:src="@drawable/yuantu"
24         android:alpha="1"
25         android:background="#f00"
26         android:scaleType="matrix"/>
27 <LinearLayout>

matrix

5.fitCenter

把图片按比例扩大(缩小)到View的宽度,居中显示。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp2.TestActivity1"
11     android:orientation="vertical">
12
13       <ImageView
14         android:layout_width="110dp"
15         android:layout_height="110dp"
16         android:src="@drawable/yuantu"
17         android:alpha="1"
18         android:background="#f00" />
19
20       <ImageView
21             android:layout_width="110dp"
22             android:layout_height="110dp"
23             android:src="@drawable/yuantu"
24             android:alpha="1"
25             android:background="#f00"
26             android:scaleType="fitCenter"/>
27 <LinearLayout >

fitCenter

6.fixEnd

把图片按比例扩大(缩小)到View的宽度,显示在View的下部分位置。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp2.TestActivity1"
11     android:orientation="vertical">
12
13       <ImageView
14         android:layout_width="110dp"
15         android:layout_height="110dp"
16         android:src="@drawable/yuantu"
17         android:alpha="1"
18         android:background="#f00" />
19
20        <ImageView
21             android:layout_width="110dp"
22             android:layout_height="110dp"
23             android:src="@drawable/yuantu"
24             android:alpha="1"
25             android:background="#f00"
26             android:scaleType="fitEnd" />
27 <LinearLayout >

fixEnd

7.fixStart

把图片按比例扩大(缩小)到View的宽度,显示在View的上部分位置。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp2.TestActivity1"
11     android:orientation="vertical">
12
13       <ImageView
14         android:layout_width="110dp"
15         android:layout_height="110dp"
16         android:src="@drawable/yuantu"
17         android:alpha="1"
18         android:background="#f00" />
19
20       <ImageView
21             android:layout_width="110dp"
22             android:layout_height="110dp"
23             android:src="@drawable/yuantu"
24             android:alpha="1"
25             android:background="#f00"
26             android:scaleType="fitStart"/>
27 <LinearLayout>

fixStart

8.fixXY

把图片按照指定的大小在View中显示,拉伸显示图片,不保持原比例,填满View。

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     xmlns:tools="http://schemas.android.com/tools"
 4     android:layout_width="match_parent"
 5     android:layout_height="match_parent"
 6     android:paddingBottom="@dimen/activity_vertical_margin"
 7     android:paddingLeft="@dimen/activity_horizontal_margin"
 8     android:paddingRight="@dimen/activity_horizontal_margin"
 9     android:paddingTop="@dimen/activity_vertical_margin"
10     tools:context="com.hanqi.testapp2.TestActivity1"
11     android:orientation="vertical">
12
13           <ImageView
14             android:layout_width="110dp"
15             android:layout_height="110dp"
16             android:src="@drawable/yuantu"
17             android:alpha="1"
18             android:background="#f00" />
19
20            <ImageView
21             android:layout_width="110dp"
22             android:layout_height="110dp"
23             android:src="@drawable/yuantu"
24             android:alpha="1"
25             android:background="#f00"
26             android:scaleType="fitXY"/>
27
28 <LinearLayout >

fixXY

时间: 2024-08-03 05:23:08

View(视图)——图片视图的相关文章

Android——图片视图(ImageView)、状态开关按钮(ToggleButton)、时钟

xml <?xml version="1.0" encoding="utf-8"?> <!--滚动视图--> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="match_pare

154在屏幕中绘图时设置透明度(扩展知识:为图片视图添加点击手势识别器,来实现点击事件操作)

一张图片,通过混合模式绘制后,能得到不同效果的图片. 这里的示例仅是测试效果:实际上可以通过不同程度的混合模式绘制,来得到符合需求的效果. 效果如下: ViewController.h 1 #import <UIKit/UIKit.h> 2 3 @interface ViewController : UIViewController 4 @property (strong, nonatomic) UIImageView *imgVBlend; 5 @property (strong, nona

02-常见控件:ImageView(图片视图)、slider(滑动器)、switch(开关)使用

效果图:       通过点击设置 将显示如第二张图所示                            第三张为项目目录文件 供参考              主要代码: // // WHBLAPViewController.h // 04-whblap查看器 // // Created by whblap on 14-6-6. // Copyright (c) 2014年 whblap. All rights reserved. // #import <UIKit/UIKit.h>

阅读《Android 从入门到精通》(20)——图片视图

图片视图(ImageView) ImageView 类属于 android.Widget 包并且继承于 android.widget.View 类,派生了 ImageButton 和 ZoomButton 等子类,主要用于对图片作相关处理.可以通过 setImageBitmap 方法或 setImageResource(int) 方法设置图片资源,或者通过 android:src 属性指定. ImageView 类方法 ImageView 示例 完整工程:http://download.csdn

UIImageView图片视图的基本概念和使用方法

IOS学习笔记(十)之UIImageView图片视图的基本概念和使用方法(博客地址: http://blog.csdn.net/developer_jiangqq ) Author:hmjiangqq Email:[email protected] UIImageView: 作用:专门用于显示图片 首先看下官方的解说: An image view object provides a view-based container for displaying either a single image

视图(View)与部分视图(Partial View)之间数据传递

写ASP.NET MVC程序,我们经常需要把数据从视图(View)传递至部分视图(Partial View) 或者相反. 今天Insus.NET使用 ControllerBase.TempData 进行处理. 首先演示的是View至Parital View创建一个控制器,并添加一个操作TmTestA(): 创建视图: 上图中标记#1,引用母版.标记#2,为TempData设置一个值.标记#3,使用Html.RenderPartial去Render一个部分视图. 创建部分视图,在部分视图中,去获取

图片视图、图片按钮和单选按钮

1 <?xml version="1.0" encoding="utf-8"?> 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 3 xmlns:tools="http://schemas.android.com/tools" 4 android:layout_width="match_parent

iOS 图片视图UIImageView小记

1关于在图片视图上添加按钮后,点击按钮没反应的问题 一般情况下是由于图片视图没有开启用户交互导致的,也有可能是按钮视图被其他视图覆盖了或者超出范围 现在是开启用户交互的代码,你要手动开启,默认是关闭的 yourImageView.userInteractionEnabled = YES

asp.net mvc View 与PartivalView视图的区别

当我们使用razor作为页面引擎时,它的视图文件扩展名为cshtml或者vbshtml,而之前作为分部视图的ascx文件,进行razor之后,也是cshtml,这与非razor引擎有些不同,在这方面,官方并没有显式把分部视图与标准视图分开,有时,我们在开发时,可能会出现一些混乱了,今天主要来说一下,如何正确的使用分部视图! 分部视图在action中返回一定要用PartialView(),而不要偷懒使用View(),因为,如果你使用View()渲染视图,系统会认为你是一个标准视图,会为你加个默认的