ANDROID_MARS学习笔记_S01_006ImageView

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了ANDROID_MARS学习笔记_S01_006ImageView相关的知识,希望对你有一定的参考价值。

一、ImageView介绍

设置scalType

Must be one of the following constant values.

ConstantValueDescription
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

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
 3     android:layout_width="match_parent"
 4     android:layout_height="match_parent"
 5     android:orientation="vertical" >
 6     
 7     <ImageView 
 8         android:id="@+id/imageViewId"
 9         android:layout_width="100dp"
10         android:layout_height="100dp"
11         android:src="@drawable/images"
12         android:scaleType="fitXY"
13         android:background="#00FF00"/>
14     
15     <ImageView
16         android:id="@+id/imageView2Id"
17         android:layout_width="100dp"
18         android:layout_height="100dp"
19         android:src="@drawable/wo"
20         android:background="#FF0000"
21         android:scaleType="fitXY"/>
22 
23 </LinearLayout>

 

2.MainActivity.java

 

 1     private ImageView iv;
 2     
 3     @Override
 4     protected void onCreate(Bundle savedInstanceState) {
 5         super.onCreate(savedInstanceState);
 6         setContentView(R.layout.imageview_layout);
 7         
 8         iv = (ImageView) findViewById(R.id.imageViewId);
 9         iv.setImageResource(R.drawable.images);
10         iv.setScaleType(ScaleType.CENTER_INSIDE);

 

以上是关于ANDROID_MARS学习笔记_S01_006ImageView的主要内容,如果未能解决你的问题,请参考以下文章

ANDROID_MARS学习笔记_S05_006_距离传感器

ANDROID_MARS学习笔记_S02_006_APPWIDGET3_AppWidget发送广播及更新AppWidget

ANDROID_MARS学习笔记_S04_006_用获取access_token,access_token_secrect

ANDROID_MARS学习笔记_S01_012_RatingBar

ANDROID_MARS学习笔记_S01_005CheckBox

ANDROID_MARS学习笔记_S01_011ProgressBar