【问题标题】:Transparent image(gif) has black background in ViewPager透明图像(gif)在 ViewPager 中具有黑色背景
【发布时间】:2015-08-24 07:51:46
【问题描述】:

我有一个有 ViewPager 的片段:

 <android.support.v4.view.ViewPager
                    android:id="@+id/pager"
                    android:layout_width="fill_parent"
                    android:layout_height="350dp"                   
                     />

适配器:

public class ImageAdapter extends PagerAdapter
...
@Override
        public Object instantiateItem(ViewGroup container, final int position) {        
            ImageView imageView = new ImageView(context);            
            imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE);
            imageView.setAdjustViewBounds(true);

            Ion.with(context)
            .load(path)
            .withBitmap()
            .intoImageView(imageView);     

            ((ViewPager) container).addView(imageView, 0);
            return imageView;
        }
...
}

如果图像是透明的,则它具有黑色背景。 为片段根视图或活动根视图设置白色背景没有帮助。

【问题讨论】:

    标签: android android-fragments android-viewpager android-ion


    【解决方案1】:

    我认为根据此链接,android 不支持透明 gif https://code.google.com/p/android/issues/detail?id=62016 所以最好使用png

    【讨论】:

    • 在没有 ViewPager 的 RelativeLayout 中加载的相同图像具有 android:background="@color/WHITE" 并且可以正常工作。
    • 但是使用 png 图像,因为 android 建议和每个人都使用相同
    猜你喜欢
    • 1970-01-01
    • 2013-11-25
    • 1970-01-01
    • 1970-01-01
    • 2016-12-29
    • 2013-09-26
    • 1970-01-01
    • 2021-04-28
    • 1970-01-01
    相关资源
    最近更新 更多