I'm now completely stumped. I have spent many hours, yet I cannot solve this. I have a view that I'm adding some text to, as well as a gradient rectangle (fades from an alpha grey to completely alpha). The first If Statement is for drawing the text and rectangle on the bottom left hand side, and the second is for the bottom right hand side (depending on the condition obviously).
This is the code:
It works as desired on the emulator. No issues. But if I run the same code on a device, it NEVER draws the bottom right hand side gradient. It draws the text, but not the rectangle...
Why on earth is it working for the emulator, and not on devices? I've tried StackOverflow, but nobody is replying...
EDIT: Sorry for the poor formatting, this might be easier to read
This is the code:
Code:
if (mCurrentPage - 1 >= 0) {
teams = ((MainActivity)getContext()).cricketGames.get(mCurrentPage - 1).getHomeCode() + " vs " +
((MainActivity)getContext()).cricketGames.get(mCurrentPage - 1).getAwayCode();
offset1 = mTeam1TextPaint.measureText(teams);
textShader1 = new LinearGradient(0, 0, 0 + offset1 + offset1, dY, Color.argb(100, 160, 160, 160), Color.alpha(0), Shader.TileMode.CLAMP);
mTeam1BackPaint.setShader(textShader1);
bg1.set(0, 0, (int)(0 + offset1 + offset1), maxY);
canvas.drawRect(bg1, mTeam1BackPaint);
canvas.drawText(teams, 0 + 8, dY + 5, mTeam1TextPaint);
}
if (mCurrentPage + 1 < count) {
teams = ((MainActivity)getContext()).cricketGames.get(mCurrentPage + 1).getHomeCode() + " vs " +
((MainActivity)getContext()).cricketGames.get(mCurrentPage + 1).getAwayCode();
offset2 = mTeam2TextPaint.measureText(teams);
textShader2 = new LinearGradient(maxX, 0, maxX - offset2 - offset2, dY, Color.argb(200, 160, 160, 160), Color.alpha(0), Shader.TileMode.CLAMP);
mTeam2BackPaint.setShader(textShader2);
bg2.set(maxX, 0, (int)(maxX - offset2 - offset2), maxY);
canvas.drawRect(bg2, mTeam2BackPaint);
canvas.drawText(teams, maxX - offset2 - 8, dY + 5, mTeam2TextPaint);
}
It works as desired on the emulator. No issues. But if I run the same code on a device, it NEVER draws the bottom right hand side gradient. It draws the text, but not the rectangle...
Why on earth is it working for the emulator, and not on devices? I've tried StackOverflow, but nobody is replying...
EDIT: Sorry for the poor formatting, this might be easier to read
Last edited: