use*_*869 3 android facebook bitmap imageview profile-picture
我无法使用此库将我的一个图像动态地制作成一个圆圈.这是我的尝试:
private void drawerSetup() {
Profile profile = Profile.getCurrentProfile();
ProfilePictureView profilePictureView = (ProfilePictureView) findViewById(R.id.profile_image);
CircularImageView circularProfilePicture = (CircularImageView) findViewById(R.id.profile_image_circle);
if(profilePictureView != null) {
profilePictureView.setProfileId(profile.getId());
ImageView imageView = ((ImageView)profilePictureView.getChildAt(0));
Bitmap bitmap = ((BitmapDrawable)imageView.getDrawable()).getBitmap();
circularProfilePicture.setImageBitmap(bitmap);
}
}
Run Code Online (Sandbox Code Playgroud)
布局:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="200dp"
xmlns:facebook="http://schemas.android.com/apk/res-auto"
xmlns:app="http://schemas.android.com/tools"
android:background="@drawable/side_nav_bar"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:theme="@style/ThemeOverlay.AppCompat.Dark"
android:orientation="vertical"
android:gravity="bottom"
app:showIn="@layout/activity_news_feed">
<com.facebook.login.widget.ProfilePictureView
android:id="@+id/profile_image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
facebook:com_facebook_preset_size="normal"
android:layout_centerHorizontal="true"
android:layout_centerVertical="true"
android:paddingBottom="8dp"
android:layout_centerInParent="true" />
<com.mikhaellopez.circularimageview.CircularImageView
android:layout_width="100dp"
android:layout_height="100dp"
app:border_color="#EEEEEE"
app:border_width="2dp"
app:shadow="true"
app:shadow_radius="10"
android:id="@+id/profile_image_circle"
app:shadow_color="#000000"
android:layout_alignBottom="@+id/profile_image"
android:layout_toLeftOf="@+id/profile_image"
android:layout_toStartOf="@+id/profile_image" />
Run Code Online (Sandbox Code Playgroud)
我知道profilePictureView当我打电话给profilePictureView.setProfileId(profile.getId());我的布局时,我的显示正确,它显示正确.但是,当我尝试调用circularProfilePicture时,我只是得到一张"空"照片.似乎没有正确识别/设置图像的位图.图像不显示profilePictureView.任何想法为什么会这样?
在使用不同的图像库(包括Picasso)之后,我完成了使用名为Fresco的 Facebook .使用更少的代码,速度更快,每个工作都应该如此.
壁画支持:
医生也这么说
在Android 4.x及更低版本中,Fresco将图像放在Android内存的特殊区域.这可以让您的应用程序运行得更快 - 并且更少经常遭受可怕的OutOfMemoryError.
它也支持圆角,你在搜索,见这里.
布局示例:
<com.facebook.drawee.view.SimpleDraweeView
android:id="@+id/avatarImageView"
android:layout_width="50dp"
android:layout_height="50dp"
fresco:placeholderImageScaleType="centerCrop"
fresco:placeholderImage="@drawable/photo_placeholder"
fresco:roundAsCircle="true"/>
Run Code Online (Sandbox Code Playgroud)
注意:不要忘记在Fresco.initialize(this);某处调用(通常在Application类中).
我还应该注意到Fresco目前使用ProGuard为您的应用程序添加了2.6Mb.如果您想要更少的功能,您可以选择使用另一个库,如Glide.
| 归档时间: |
|
| 查看次数: |
7002 次 |
| 最近记录: |