This question may seem trivial and been asked many times, but I couldn't find an answer that will work for me.
I have an ImageView
and GLSurfaceView
that is drawn on top of ImageView
when I push a button.
For my ImageView
I pass a Bitmap
and scale it down in order to avoid an OutOfMemoryError
exception. My ImageView
is aligned to other elements in my UI, so it stretches the image to fill width/height (this is what I want).
When I change from ImageView
to GLSurfaceView
I get black regions around my image that used to be transparent in my ImageView
, because GLSurfaceView
makes a hole in UI and works differently than usual elements it draws background of my image to black and I don't need it, because I have custom background.
I came down with a solution to set LayoutParams
for GLSurfaceView
programmatically and I use Bitmap
width and height, but I end up with a smaller image. I need the exact width and height of the image displayed - not the ImageView
because it has transparent regions.
PS: I'm not an OpenGL expert and if you have a solution that works for OpenGL please share it.
a)
_______________
| |
| |
|---------------| <-
| transparent |
|---------------| <- Entire
| | ImageView
| Image | need
| | only this
|---------------| <-
| transparent |
|---------------| <-
| |
---------------
b)
_______________
| |
| |
|---------------| <-
| black |
|---------------|
| |
| Image | GLSurfaceView
| |
|---------------|
| black |
|---------------| <-
| |
---------------
My ImageView
and GLSurfaceView
:
<android.opengl.GLSurfaceView
android:id="@+id/glsvImageHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/horScrollImage"
android:layout_marginBottom="5dp"
android:layout_marginTop="50dp"
android:visibility="invisible" />
<ImageView
android:id="@+id/ivImageHolder"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_above="@+id/horScrollImage"
android:layout_marginBottom="5dp"
android:layout_marginTop="50dp"
android:visibility="visible" />