Imagedrawable不适合imageview

时间:2015-03-04 05:53:16

标签: android imageview drawable scaling

从缓存中获取的图像在回到活动之前的状态时不适合ImageView,它在创建活动时正确显示但是当我进行其他活动时ImageView大小不同以及当我按回drawable时不适合在ImageView中

xml ImageView就像

<ImageView
    android:id="@+id/user_image"
    android:layout_width="60dip"
    android:layout_height="60dip"
    android:layout_below="@+id/progress"
    android:layout_marginLeft="10dp"
    android:layout_marginTop="15dp"
    android:adjustViewBounds="true"
    android:background="@drawable/user_default"
    android:scaleType="fitXY" />

我正在从LRUCahce加载BitmapDrawable,它获取位图并将其转换为BitmapDrawable并将其设置为Image,如

private void setImageDrawable(ImageView imageView, Drawable drawable)
{
    if (mFadeInBitmap)
    {
        // Transition drawable with a transparent drawable and the final
        // drawable
        final TransitionDrawable td = new TransitionDrawable(new Drawable[]
        { new ColorDrawable(android.R.color.transparent), drawable });
        // Set background to loading bitmap
        if (Build.VERSION.SDK_INT >= 16)
        {
            imageView.setBackground(new BitmapDrawable(mResources, mLoadingBitmap));
        } else
        {
            imageView.setBackgroundDrawable(new BitmapDrawable(mResources, mLoadingBitmap));
        }

        imageView.setImageDrawable(td);
        td.startTransition(FADE_IN_TIME);
    } else
    {
        imageView.setImageDrawable(drawable);
    }
}

enter image description here

0 个答案:

没有答案