一、ImageView介绍

设置scalType

Must be one of the following constant values.

Constant Value Description
matrix 0 Scale using the image matrix when drawing. See setImageMatrix(Matrix).
fitXY 1 Scale the image using FILL.
fitStart 2 Scale the image using START.
fitCenter 3 Scale the image using CENTER.
fitEnd 4 Scale the image using END.
center 5 Center the image in the view, but perform no scaling.
centerCrop 6 Scale the image uniformly (maintain the image's aspect ratio) so both dimensions (width and height) of the image will be equal to or larger than the corresponding dimension of the view (minus padding). The image is then centered in the view.
centerInside 7 Scale the image uniformly (maintain the image's aspect ratio) so that both dimensions (width and height) of the image will be equal to or less than the corresponding dimension of the view (minus padding). The image is then centered in the view.

This corresponds to the global attribute resource symbol scaleType.

二、
1.activity_main.xml

 <?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" > <ImageView
android:id="@+id/imageViewId"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/images"
android:scaleType="fitXY"
android:background="#00FF00"/> <ImageView
android:id="@+id/imageView2Id"
android:layout_width="100dp"
android:layout_height="100dp"
android:src="@drawable/wo"
android:background="#FF0000"
android:scaleType="fitXY"/> </LinearLayout>

2.MainActivity.java

     private ImageView iv;

     @Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.imageview_layout); iv = (ImageView) findViewById(R.id.imageViewId);
iv.setImageResource(R.drawable.images);
iv.setScaleType(ScaleType.CENTER_INSIDE);

ANDROID_MARS学习笔记_S01_006ImageView的更多相关文章

  1. ANDROID_MARS学习笔记_S01_012_RatingBar

    1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...

  2. ANDROID_MARS学习笔记_S01_012_SeekBar

    1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...

  3. ANDROID_MARS学习笔记_S01_011ProgressBar

    文档是这样来设置样式 <ProgressBar android:layout_width="wrap_content" android:layout_height=" ...

  4. ANDROID_MARS学习笔记_S01_010日期时间控件

    1.xml <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns: ...

  5. ANDROID_MARS学习笔记_S01_009Relative_LAYOUT例子

    1. <?xml version="1.0" encoding="utf-8"?> <RelativeLayout xmlns:android ...

  6. ANDROID_MARS学习笔记_S01_008Linear_layout例子

    1.netstone_layout.xml <?xml version="1.0" encoding="utf-8"?> <LinearLay ...

  7. ANDROID_MARS学习笔记_S01_007Linear_layout嵌套与layout_weight的设置

    一.介绍 二.1.linear_layout.xml <?xml version="1.0" encoding="utf-8"?> <Line ...

  8. ANDROID_MARS学习笔记_S01_005CheckBox

    一. 1.checkbox_layout.xml <?xml version="1.0" encoding="utf-8"?> <Linear ...

  9. ANDROID_MARS学习笔记_S01_004dpi、dp(dip)及计算

    一.dpi.dp介绍 sp会随着用户在手机中设置字体大小而改变,而dp不会 二.1.dpsp_layout.xml <?xml version="1.0" encoding= ...

随机推荐

  1. es5 和 es6 class

    // ES5 function User(name,age) { this.name = name; this.age = age; } // 静态方法 User.getClassName = fun ...

  2. css3学习笔记之2D转换

    translate() 方法 translate()方法,根据左(X轴)和顶部(Y轴)位置给定的参数,从当前元素位置移动. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ...

  3. jQuery中的getter和setter方法

    1.attr()方法是jQuery中用于HTML属性的getter/setter.一个相关函数是removeAttr(). 2.css()方法和attr()方法很类似,只是css()方法作用于元素的c ...

  4. HDU 2340 Obfuscation(dp)

    题意:已知原串(长度为1~1000),它由多个单词组成,每个单词除了首尾字母,其余字母为乱序,且句子中无空格.给定n个互不相同的单词(1 <= n <= 10000),问是否能用这n个单词 ...

  5. JS 框架

    <html xmlns=”http://www.w3.org/1999/xhtml”> <head> <title>Untitled Page</title& ...

  6. Open Live Writer增加代码插件

          作为一名程序员,免不了和代码打交道,自然在写博客的时候,也会用到代码的展示,Open Live Writer确实是一个不错的工具,不用再去登录博客的后台,就可以在本地进行文章的编写,但是致 ...

  7. 获取客户端访问的ip地址

    function real_ip() { static $realip = NULL; if ($realip !== NULL) { return $realip; } if (isset($_SE ...

  8. checkBox控件的CheckedChanged与CheckedStateChanged区别

    Checked属性为bool类型,CheckState属性为枚举类型(CheckState.Checked.CheckState.Unchecked和CheckState.Indeterminate) ...

  9. PHP将二进制文件存入数据库以及从数据库中读取二进制文件

    <?php $file = 'abcd.sqlite'; mysql_connect('localhost','root','123456'); mysql_select_db('zblog') ...

  10. Django文档——Model中的ForeignKey,ManyToManyField与OneToOneField

    关联关系字段 (Relationship fields) ForeignKey,ManyToManyField与OneToOneField分别在Model中定义多对一,多对多,一对一关系. 例如,一本 ...