阅读五分钟,每日十点,和您一起终身学习,这里是程序员Android
本篇文章主要介绍 Android 开发中的部分知识点,通过阅读本篇文章,您将收获以下内容:
一、ImageView 的继承关系
二、ImageView 常用方法
三、ImageView 背景 间距属性设置
四、使用Bitmap 类型动态设置ImageView 资源
五、ImageView 图片倒影实现
六、ImageView 图片缩放实现
七、ImageView 圆角图片实现
八、Bitmap 与Drawable 转换工具类
一、ImageView 的继承关系
ImageView的继承关系 如下:
java.lang.Object
↳ android.view.View
↳ android.widget.ImageView
二、ImageView 常用方法
ImageView主要用于显示图像资源,Bitmap或Drawable资源,同时也常用于图片渲染调色,图片缩放剪裁等。
以下XML代码段是使用ImageView显示图像资源的常见示例:
在xml使用ImageView 控件
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/ic_launcher"
/>
三、 ImageView 背景 间距属性设置
在xml使用ImageView控件
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="@color/grey"
android:padding="5dp"
android:src="@drawable/ic_launcher" />
实现效果如下:
四、 使用Bitmap 类型动态设置ImageView 资源
在xml 使用ImageView控件
android:id="@+id/img_1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:padding="5dp" />
2.java 类实现
// 1.从资源中获取Bitmap
ImageView mImageView1 = (ImageView) findViewById(R.id.img_1);
DrawableUtils.UseBitmap(this, mImageView1, R.drawable.gril);
3.DrawableUtils类方法实现
// 1.从资源中获取Bitmap
public static void UseBitmap(Context context, ImageView imageView, int drawableId) {
Bitmap bitmap = BitmapFactory.decodeResource(context.getResources(),
drawableId);
imageView.setImageBitmap(bitmap);
}
实现效果如下:
五、ImageView 图片倒影实现
在xml使用ImageView 控件
android:id="@+id/img_4"