I have an app for my own use to communicate with arduino. There are custom shape buttons, so i drawn them in PNG as single background, added Buttons
with android:background="@android:color/transparent"
to make them transparent on top almost the size of custom buttons.
In this image you can see: 1. Background - black background with dark blue buttons drawn as single png. 2. Orange png - same size as background, drawing it with match parrent
option. 3. Invisible button - with transparent option, blue square, there are 7 of them.
To eliminate misplacing of indication images i drawn them same size of background in PNG transparent background. I added them to res/drawable
and in layout XML as ImageView
with android:visibility="gone"
, the Layout is FrameLayout
. To indicate that button was pressed i make set VISIBLE
of orange custom button, and when arduino turns on output, sends back confirmation i make i gone and set visible another PNG. It costs a lot of memory. The images dimensions are 1478x2623. At once in worst case i have to show only 8 images + background permanently. And in onCreate method i load all 17 images.
To avoid OOM - out of memory error, i have to resize images and it gives me bad looking...
If visibility of image in XML is android:visibility="gone"
, does it load the image in onCreate? If so, i should create, scale it, and draw only when needed. How to achieve that?
EDIT
Made some changes.
- Images reduced to 1920x1080
- 8 ImageView left on layout and resources are set in method, not in XML
These changes made it faster and no more OOM error. At the moment i am very busy so it will take some time to test methods suggested in answers. I will try ASAP.