Glide

一、加载Gif图片
效果图:

实现步骤:
    第一步: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'
 将.gif放到drawable-xhdpi中或从网络获取
import com.bumptech.glide.Glide;
ImageView imageView = (ImageView) findViewById(R.id.imageview);
Glide.with(this).load(R.drawable.nuli).into(imageView);

二、实现毛玻璃效果
效果图:

  第一步: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);




  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值