Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

My android imageView is black no matter what

I try to display an ImageView into my app on a well (hopefully) defined view (XML)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activityShowLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="#73C310"
android:orientation="vertical"
tools:context=".ShowActivity" >

<ImageView
    android:id="@+id/mainImage"
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_above="@+id/moodButton"
    android:layout_alignParentLeft="true"
    android:layout_alignParentRight="true"
    android:layout_alignParentTop="true"
    android:layout_margin="12dp"
    android:background="#000"
    android:src="@drawable/gs_04_pic" />

<!-- ... -->

and after that in my onCreate method on the activity

    @Override
public void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);

    setContentView(R.layout.activity_show);

    /* ... blabla bla ... */

    ImageView imageView = (ImageView) findViewById(R.id.mainImage);

    Bitmap bitmap = BitmapFactory.decodeByteArray(cream.getMedia(), 0, cream.getMedia().length);
    Drawable draw = new BitmapDrawable(getResources(), bitmap);
    imageView.setImageDrawable(draw);
    imageView.invalidate();
}

with cream.getMedia() returning a valid byte[] (from database) which I can log giving me:

07-18 17:41:16.812: I/app(9883): byte[] is: [B@414af0b0

But at the end the imageView is black (no image on it) If I don't run the onCreate code it displays the resource set in the XML (on black background as set in XML too)

What is wrong?

like image 783
jrmgx Avatar asked Oct 15 '25 15:10

jrmgx


1 Answers

I run into this problem, in my case the problem came from the config in:

bluid.gradle

shrinkResources true

It deleted my files because I didn't have a static reference to my resources. (images in my case)

so I found this article "Keeping Resources" in this link Resource Shrinking

In resumen it says: you should make a file in this path "/res/raw/keep.xml"

<?xml version="1.0" encoding="utf-8"?>
<resources xmlns:tools="http://schemas.android.com/tools"
  tools:keep="@layout/l_used*_c,@layout/l_used_a,@layout/l_used_b*"/>
like image 77
Blaaz Avatar answered Oct 18 '25 07:10

Blaaz