So, my general issue is that I'm trying to dynamically set imageButton images based on grabbing an 80 x 80 area of a number of 400 x 600 png Drawables, layer them, and imageButton.setImageDrawable() them into the buttons. This actually works...assuming the device has a large screen. For small screens (read: phones) this fails. Granted, I have only tested "large screens" for BlueStacks, however the fail on Small Screens has effected my Nexus 5 emmulater, a friend's Turbo, and my new (two months old maybe) Turbo 2.
a Picture showing buttons with faces for BlueStacks but nothing for a Phone in the emmulator
As for Code...the following is the interior of the for loop that creates the buttons:
Drawable[] layers = new Drawable[8];
faceMaker(layers);
layers[1] = changeColor(layers[1], Color.parseColor("#" + listChoice.get(nN -1 + nAdd).toString().substring(1, 7)));
layers[2] = changeColor(layers[2], Color.parseColor(CharacterDatabase.getColor(156)));
layers[3] = changeColor(layers[3], Color.parseColor(CharacterDatabase.getColor(155)));
layers[4] = changeColor(layers[4], Color.parseColor("#" + listChoice.get(nN -1 + nAdd).toString().substring(1, 7)));
layers[5] = changeColor(layers[5], Color.parseColor("#" + listChoice.get(nN -1 + nAdd).toString().substring(1, 7)));
layers[6] = changeColor(layers[6], Color.parseColor(CharacterDatabase.getColor(155)));
layers[7] = changeColor(layers[7], Color.parseColor(CharacterDatabase.getColor(155)));
layers[0] = changeColor(layers[0], Color.parseColor(CharacterDatabase.getColor(155)));
LayerDrawable layerDrawable = new LayerDrawable(layers);
btnChoice[nN].setImageDrawable(layerDrawable);
nBtnAct[nN] = 1;
Where "faceMaker" grabs drawables from reasources, uses setBounds to grab the 80 by 80 area of the drawable that corresponds to what you see (the full drawables are layered above, with other things layered and added on, see the left-hand image for a sense of the size difference); here's a sample from faceMaker():
int id = imgApp.getContext().getResources().getIdentifier(sSex.substring(0, 1) + "hair" + Integer.toString(CharacterDatabase.getSlot(7)), "drawable", imgApp.getContext().getPackageName());
layers[0] = ContextCompat.getDrawable(imgApp.getContext(), id).mutate();
layers[0] = new BitmapDrawable(imgApp.getContext().getResources(), Bitmap.createBitmap(((BitmapDrawable) layers[0]).getBitmap(), nFaceStartX, nFaceStartY, nFaceX, nFaceY));
layers[0].mutate();
So, my question is...why does this work on larger screens, but fail so terribly on smaller ones? Had a similar issue with a different button (1 Drawable) that was displaying only a part of the Drawable; fixed a setBounds issue to resolve that, however, i need to be able to grab only the head for my buttons, so that won't work for the overall faceMaker/button solution.
Is this a setBounds issue? If so, how do I resolve it and yet still grab the 80 by 80 area I need? (nFaceStartx, nFacex, etc. are the bounds that find the 80 by 80 area). if not, then what causes this? And how do I fix it in code?
Edit: Added a line Log.e("width", Integer.toString(layerDrawable.getIntrinsicWidth()) + " " + Integer.toString(btnChoice[nN].getWidth()));
..which spit back "width 80 50" on Bluestacks (where it works) and "width 80 150" on the phone-emulator, where it doesn't display. No idea why that may be occuring, but there it is, in case that matters. The layout:width and layout:height are both 50dp in the xml.