一、加载Gif图片
效果图:
![](https://i-blog.csdnimg.cn/blog_migrate/d1dbe8f3ddef577cdd99730aeffd40a5.png)
实现步骤:
第一步:xml布局添加ImageView
- <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
- xmlns:app="http://schemas.android.com/apk/res-auto"
- xmlns:tools="http://schemas.android.com/tools"
- android:layout_width="match_parent"
- android:layout_height="match_parent"
- android:orientation="vertical"
- tools:context=".MainActivity">
- <ImageView
- android:id="@+id/imageview"
- android:layout_width="wrap_content"
- android:layout_height="wrap_content" />
- </LinearLayout>
第二步:添加第三方控件
- compile 'com.github.bumptech.glide:glide:3.7.0'
- import com.bumptech.glide.Glide;
- ImageView imageView = (ImageView) findViewById(R.id.imageview);
- Glide.with(this).load(R.drawable.nuli).into(imageView);
二、实现毛玻璃效果
效果图:
![](https://i-blog.csdnimg.cn/blog_migrate/ec830fc89f8479e80530ee510c3a7cbc.png)
第一步:xml布局添加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">
- <RelativeLayout
- android:layout_width="match_parent"
- android:layout_height="wrap_content">
- <ImageView android:id="@+id/iv_blur"
- android:layout_width="match_parent"
- android:layout_height="200dp" />
- <ImageView android:id="@+id/iv_avatar"
- android:layout_width="60dp"
- android:layout_height="60dp"
- android:layout_centerInParent="true"/>
- </RelativeLayout>
- </LinearLayout>
- compile 'jp.wasabeef:glide-transformations:2.0.1'
- compile 'com.github.bumptech.glide:glide:3.7.0'
- package com.example.lvfulong.myapplication;
- import android.support.v7.app.AppCompatActivity;
- import android.os.Bundle;
- import android.widget.ImageView;
- import com.bumptech.glide.Glide;
- import com.bumptech.glide.load.resource.bitmap.CenterCrop;
- import jp.wasabeef.glide.transformations.BlurTransformation;
- import jp.wasabeef.glide.transformations.RoundedCornersTransformation;
- public class MainActivity extends AppCompatActivity {
- private ImageView blurImageView;
- private ImageView avatarImageView;
- @Override
- protected void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.activity_main);
- initView();
- initData();
- }
- private void initView() {
- blurImageView = (ImageView) findViewById(R.id.iv_blur);
- avatarImageView = (ImageView) findViewById(R.id.iv_avatar);
- }
- private void initData() {
- // Glide.with(this).load(R.drawable.work_routine_report_feedback)
- // .bitmapTransform(new BlurTransformation(this, 25), new CenterCrop(this))
- // .into(blurImageView);
- Glide.with(this).load("http://b.hiphotos.baidu.com/album/pic/item/caef76094b36acafe72d0e667cd98d1000e99c5f.jpg?psign=e72d0e667cd98d1001e93901213fb80e7aec54e737d1b867")
- .bitmapTransform(new BlurTransformation(this, 25), new CenterCrop(this))
- .into(blurImageView);
- //可设置圆角mag的图片
- Glide.with(this).load(R.drawable.work_routine_report_feedback)
- .bitmapTransform(new RoundedCornersTransformation(this, 5, 10))
- .into(avatarImageView);
- }
- }
- <uses-permission android:name="android.permission.INTERNET" />
补充:
- // Glide.with(this).load("http://img2.3lian.com/2014/f6/173/d/51.jpg").error(R.drawable.work_routine_report_feedback).into(avatarImageView);
- //圆形
- // Glide.with(this).load(R.drawable.work_routine_report_feedback)
- // .bitmapTransform(new CropCircleTransformation(this))
- // .into(avatarImageView);
- //方形
- // Glide.with(this).load(R.drawable.work_routine_report_feedback)
- // .bitmapTransform(new CropTransformation(this))
- // .into(avatarImageView);
- //方形可以改变颜色
- // Glide.with(this).load(R.drawable.work_routine_report_feedback)
- // .bitmapTransform(new ColorFilterTransformation(this,R.color.colorPrimary))
- // .into(avatarImageView);
- // Glide.with(this).load(R.drawable.work_routine_report_feedback)
- // .bitmapTransform(new CropSquareTransformation(this))
- // .into(avatarImageView);
- //将图片改成灰色图片
- // Glide.with(this).load(R.drawable.work_routine_report_feedback)
- // .bitmapTransform(new GrayscaleTransformation(this))
- // .into(avatarImageView);