使用Picasso和Glide获取黑色ImageView [英] Getting black ImageView using Picasso and Glide

查看:269
本文介绍了使用Picasso和Glide获取黑色ImageView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

问题



我正在编写一个应该有幻灯片功能的Android应用。我找到了基于Picasso的



我从我的drawables中加载本地资源中的图像。有时它会在纵向模式下发生,有时在横向模式下发生。我使用哪种图像无关紧要,有时会出现黑度。



编辑:




  • 我正在使用Android 5.0.2和4.4.2 - 它似乎不会发生在4.4.2上。仅限5.0.2。


  • 它发生在带有Android 5.1的Moto X 2014上。


  • 我正在尝试加载的图像在磁盘上有45KB,分辨率为900x445。


  • 我已打开布局根据建议,这些是结果:






滚动时保持这样。





有时,它会变成白色而不是黑色(或白色,然后是黑色)。





我还有别的东西ried:当我将文件从该文件夹更改为 res /时,我的drawables位于 res / drawable 文件夹中drawable-xxxhdpi 滑块适用于5.0.2设备。 wtf ???



到目前为止我尝试了什么



我尝试过不同的图像,在幻灯片上加载多个图像,甚至这个拉取请求,将lib上的Picasso改为Glide。似乎没有任何作用,错误似乎是随机的。



一旦我尝试使用网络上的网址而不是本地存储上的实际可绘制网址,工作。使用完全相同的图像。



以下是我加载图片的方式:



Fragment.java

 私人SliderLayout滑块; 
私人PagerIndicator指标;

// ...

private void setupSlider(){

HashMap< String,Integer> file_maps = new HashMap<>();

file_maps.put(Blah,R.drawable.banner_1);
file_maps.put(Bleh,R.drawable.banner_2);
file_maps.put(Blih,R.drawable.banner_3);
file_maps.put(Bloh,R.drawable.banner_4);

for(String name:file_maps.keySet()){

DefaultSliderView dsv = new DefaultSliderView(getActivity());

dsv.description(name)
.image(file_maps.get(name))
.error(R.drawable.banner_error)
.empty(R。 drawable.empty)
.setScaleType(BaseSliderView.ScaleType.Fit)
.setOnSliderClickListener(this);

//添加你的额外信息
dsv.bundle(new Bundle());
dsv.getBundle()
.putString(extra,name);

slider.addSlider(dsv);
}

slider.setPresetTransformer(SliderLayout.Transformer.Default);
slider.setCustomIndicator(指标);
slider.setCustomAnimation(new DescriptionAnimation());
slider.setDuration(4000);
slider.addOnPageChangeListener(this);

}

fragment.xml

 < RelativeLayout 
xmlns:android =http://schemas.android.com/apk/res/android
xmlns:tools =http://schemas.android.com/tools
xmlns:custom =http://schemas.android.com/apk/res-auto
tools:context =com.example.fragments.Fragment
android:layout_width =wrap_content
android:layout_height =wrap_content>

< ScrollView
android:layout_width =wrap_content
android:layout_height =wrap_content
android:id =@ + id / sv_main>

< RelativeLayout
android:layout_width =match_parent
android:layout_height =wrap_content
android:id =@ + id / rl_main>

< com.daimajia.slider.library.SliderLayout
android:id =@ + id / slider
android:layout_width =match_parent
android :layout_height =200dp
/>
< com.daimajia.slider.library.Indicators.PagerIndicator
android:id =@ + id / custom_indicator
android:layout_width =wrap_content
android:layout_height =wrap_content
android:layout_alignParentEnd =true
android:layout_alignParentRight =true
android:layout_below =@ + id / slider
custom:shape =椭圆形
custom:selected_color =#00BFA5
custom:unselected_color =#55333333
custom:selected_pa​​dding_left =@ dimen / spacing_medium
custom:selected_pa​​dding_right =@ dimen / spacing_medium
custom:selected_pa​​dding_top =3dp
custom:selected_pa​​dding_bottom =@ dimen / spacing_small
custom:unselected_pa​​dding_left =@ dimen / spacing_medium
custom:unselected_pa​​dding_right =@扪/ spacing_mediu m
custom:unselected_pa​​dding_top =@ dimen / spacing_small
custom:unselected_pa​​dding_bottom =4dp
custom:selected_width =@ dimen / spacing_medium
custom:selected_height = @ dimen / spacing_medium
custom:unselected_width =6dp
custom:unselected_height =6dp
/>

< LinearLayout
android:orientation =vertical
android:layout_width =match_parent
android:layout_height =match_parent
android: layout_below =@ + id / custom_indicator
android:id =@ + id / ll_main_body>

< / LinearLayout>

< / RelativeLayout>

< / ScrollView>

<! - 其他内容 - >

< / RelativeLayout>

我正在关注教程 wiki页面。并且LogCat上没有任何错误,这使得解决起来更加困难。



任何想法?

解决方案

在该文件夹中创建一个名为drawable-nodpi的资源文件夹放置图像而不是不同的文件夹或可绘制文件夹。


The problem

I'm writing an Android app that's supposed to have a "Slideshow" feature on it. I've found this nice library, based on Picasso, that does exactly what I wanted, and it worked just fine most of the times.

Problem is, sometimes my images are not loaded into the slide ImageView... It only shows a "black canvas" as you can see on the screenshot below.

I am loading the image from a local resource from my drawables. Sometimes it happens on Portrait mode, sometimes on Landscape mode. It doesn't matter which image I use, sometimes that "blackness" happens.

EDIT:

  • I'm using Android 5.0.2 and 4.4.2 - It doesn't seem to happen on 4.4.2. Only on 5.0.2.

  • It happened on a Moto X 2014 with android 5.1.

  • The images I'm trying to load have 45KB on disk with a resolution of 900x445.

  • I've turned on the layout rects as suggested, and these were the results:

And it keep like that on scroll.

And sometimes, it gets white instead of black (Or white, then black).

Something else I tried: My drawables were located on the res/drawable folder, when I've changed the files from that folder to the res/drawable-xxxhdpi the slider worked on the 5.0.2 device. wtf???

What have I tried so far

I've tried different images, to load multiple images on the slide, and even this pull request that changes Picasso to Glide on the lib. Nothing seems to work and the error seems random.

Once I've tried to use URLs from the web instead of the actual drawables on the local storage, it worked. With the exact same images.

Here's how I'm loading the images:

Fragment.java

private SliderLayout slider;
private PagerIndicator indicator;

// ...

private void setupSlider() {

    HashMap<String,Integer> file_maps = new HashMap<>();

    file_maps.put("Blah",R.drawable.banner_1);
    file_maps.put("Bleh",R.drawable.banner_2);
    file_maps.put("Blih",R.drawable.banner_3);
    file_maps.put("Bloh",R.drawable.banner_4);

    for (String name : file_maps.keySet()) {

        DefaultSliderView dsv = new DefaultSliderView(getActivity());

        dsv.description(name)
                .image(file_maps.get(name))
                .error(R.drawable.banner_error)
                .empty(R.drawable.empty)
                .setScaleType(BaseSliderView.ScaleType.Fit)
                .setOnSliderClickListener(this);

        //add your extra information
        dsv.bundle(new Bundle());
        dsv.getBundle()
                .putString("extra",name);

        slider.addSlider(dsv);
    }

    slider.setPresetTransformer(SliderLayout.Transformer.Default);
    slider.setCustomIndicator(indicator);
    slider.setCustomAnimation(new DescriptionAnimation());
    slider.setDuration(4000);
    slider.addOnPageChangeListener(this);

}

fragment.xml

<RelativeLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    xmlns:custom="http://schemas.android.com/apk/res-auto"
    tools:context="com.example.fragments.Fragment"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content">

    <ScrollView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/sv_main">

        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:id="@+id/rl_main">

            <com.daimajia.slider.library.SliderLayout
                android:id="@+id/slider"
                android:layout_width="match_parent"
                android:layout_height="200dp"
                />
            <com.daimajia.slider.library.Indicators.PagerIndicator
                android:id="@+id/custom_indicator"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_alignParentEnd="true"
                android:layout_alignParentRight="true"
                android:layout_below="@+id/slider"
                custom:shape="oval"
                custom:selected_color="#00BFA5"
                custom:unselected_color="#55333333"
                custom:selected_padding_left="@dimen/spacing_medium"
                custom:selected_padding_right="@dimen/spacing_medium"
                custom:selected_padding_top="3dp"
                custom:selected_padding_bottom="@dimen/spacing_small"
                custom:unselected_padding_left="@dimen/spacing_medium"
                custom:unselected_padding_right="@dimen/spacing_medium"
                custom:unselected_padding_top="@dimen/spacing_small"
                custom:unselected_padding_bottom="4dp"
                custom:selected_width="@dimen/spacing_medium"
                custom:selected_height="@dimen/spacing_medium"
                custom:unselected_width="6dp"
                custom:unselected_height="6dp"
                />

            <LinearLayout
                android:orientation="vertical"
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_below="@+id/custom_indicator"
                android:id="@+id/ll_main_body">

            </LinearLayout>

        </RelativeLayout>

    </ScrollView>

    <!-- Other stuff -->

</RelativeLayout>

I'm following the tutorial from the libs wiki page. And no errors are being thrown on the LogCat, which is making this a lot harder to solve.

Any ideas?

解决方案

Create A Resource Folder Named drawable-nodpi in that folder put your images instead of different folders or drawable folder.

这篇关于使用Picasso和Glide获取黑色ImageView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆