android– 在FloatingActionButton Glide V4上显示为正方形的阴影

android– 在FloatingActionButton Glide V4上显示为正方形的阴影,第1张

概述我最近将Glide升级到版本4,这导致我在浮动 *** 作按钮中显示的图像出现问题.我尝试了两种方法,并且我使用相同的XML:XML:<android.support.design.widget.FloatingActionButtonandroid:id="@+id/profilepic_fab"android:layout_width="150dp"android:layout_height="1

我最近将GlIDe升级到版本4,这导致我在浮动 *** 作按钮中显示的图像出现问题.我尝试了两种方法,并且我使用相同的XML:

XML:

<androID.support.design.Widget.floatingActionbutton    androID:ID="@+ID/profilepic_fab"    androID:layout_wIDth="150dp"    androID:layout_height="150dp"    androID:scaleType="center"    app:layout_anchor="@ID/appbar"    app:layout_anchorGravity="bottom|center_horizontal"    app:srcCompat="@mipmap/bookmark_checked_white" />

方法#1:

            Requestoptions optionsCentre = new Requestoptions()                    .placeholder(R.drawable.profilepic_placeholder)                    error(R.drawable.profilepic_placeholder).donttransform()                    .dontAnimate().CircleCrop();            GlIDe.with(context)                    .load(userinfo.getprofilePic())                    .apply(optionsCentre)                    .into(profilepic);

方法#1的结果:它在AndroID 7.1.2上看起来不错,但在4.4上看起来如下图所示:

方法#2:

Requestoptions options = new Requestoptions()                .fitCenter()                .placeholder(R.drawable.profilepic_placeholder)                .error(R.drawable.profilepic_placeholder)                .priority(Priority.HIGH);    GlIDe.with(context)            .asBitmap()            .apply(options)            .load(url)            .into(new BitmAPImageVIEwTarget(fab) {                @OverrIDe                protected voID setResource(Bitmap resource) {                    RoundedBitmapDrawable circularBitmapDrawable =                            RoundedBitmapDrawableFactory.create(context.getResources(), resource);                    circularBitmapDrawable.setCircular(true);                    fab.setimageDrawable(circularBitmapDrawable);                }            });

方法#2的结果:AndroID 7.1.2和4.4的结果看起来不同

AndroID 7.1.2:

AndroID 4.4:

方法#2是以前使用GlIDe v3 …任何帮助将不胜感激!

解决方法:

使用floatingActionbutton,它无法实现所有AndroID版本的预期行为.

使用ImageVIEw和第三方库(如Picasso或Glide)来加载和转换Image资源,而不是floatingActionbutton.您也可以使用CircleImageView库.

SolUTION 1:

将ImageVIEw与Picasso一起使用.

摇篮:

dependencIEs {    .........    compile 'com.squareup.picasso:picasso:2.5.2'}

用法:

XML

<?xml version="1.0" enCoding="utf-8"?><relativeLayout 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">    <ImageVIEw        androID:ID="@+ID/image_header"        androID:layout_wIDth="match_parent"        androID:layout_height="200dp"        androID:background="@drawable/dummy_background"/>    <ImageVIEw        androID:ID="@+ID/image_profile_pic"        androID:layout_wIDth="150dp"        androID:layout_height="150dp"        androID:layout_margintop="125dp"        androID:layout_centerHorizontal="true"/></relativeLayout>

JAVA

ImageVIEw imageProfilePic = (ImageVIEw) findVIEwByID(R.ID.image_profile_pic);Picasso.with(this)        .load(R.drawable.dummy_profile_pic)        .resize(150, 150)        .centerCrop()        .transform(new Circletransform())        .into(imageProfilePic);

OUTPUT:

SolUTION 2:

使用带有GlIDe的ImageVIEw.

摇篮:

dependencIEs {    .........    compile 'com.github.bumptech.glIDe:glIDe:4.0.0-RC1'}

用法:

XML

<?xml version="1.0" enCoding="utf-8"?><relativeLayout 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">    <ImageVIEw        androID:ID="@+ID/image_header"        androID:layout_wIDth="match_parent"        androID:layout_height="200dp"        androID:background="@drawable/dummy_background"/>    <ImageVIEw        androID:ID="@+ID/image_profile_pic"        androID:layout_wIDth="150dp"        androID:layout_height="150dp"        androID:layout_margintop="125dp"        androID:layout_centerHorizontal="true"/></relativeLayout>

JAVA

ImageVIEw imageProfilePic = (ImageVIEw) findVIEwByID(R.ID.image_profile_pic);GlIDe.with(this)        .load(R.drawable.dummy_profile_pic)        .apply(Requestoptions.circleCroptransform())        .into(imageProfilePic);

OUTPUT:

SolUTION 3:

使用circleimageVIEw库.

摇篮:

dependencIEs {    .........    compile 'de.hdodenhof:circleimagevIEw:2.1.0'}

用法:

XML

<?xml version="1.0" enCoding="utf-8"?><relativeLayout 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">    <ImageVIEw        androID:ID="@+ID/image_header"        androID:layout_wIDth="match_parent"        androID:layout_height="200dp"        androID:background="@drawable/dummy_background"/>    <de.hdodenhof.circleimagevIEw.circleimageVIEw        xmlns:app="http://schemas.androID.com/apk/res-auto"        androID:ID="@+ID/image_profile_pic"        androID:layout_wIDth="150dp"        androID:layout_height="150dp"        androID:layout_margintop="125dp"        androID:layout_centerHorizontal="true"                app:civ_border_wIDth="2dp"        app:civ_border_color="#FFFFFF"/></relativeLayout>

JAVA

circleimageVIEw imageProfilePic = (circleimageVIEw) findVIEwByID(R.ID.image_profile_pic);Picasso.with(this)        .load(R.drawable.dummy_profile_pic)        .into(imageProfilePic);

OUTPUT:

希望这会有所帮助〜

总结

以上是内存溢出为你收集整理的android – 在FloatingActionButton Glide V4上显示为正方形阴影全部内容,希望文章能够帮你解决android – 在FloatingActionButton Glide V4上显示为正方形的阴影所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/web/1108737.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-29
下一篇 2022-05-29

发表评论

登录后才能评论

评论列表(0条)

保存