Setting view alpha in runtime is slow, how to speed it up? - android

I have two ImageViews which I hope imageViewA is overlapped by imageViewB, and when user select a seekbar, the alpha value of imageViewB will change accordingly (e.g., becoming translucent and users can see part of imageViewA).
It supposes to be a easy coding task, however I found the performance is VERY slow in my Galaxy S6.
I have tried all setAlpha(int), setAlpha(float), and setImageAlpha(float), but get no hope. It seems the most related question post is App UI operations (setting alpha, setting margins, etc.) very slow on 4.4.4 compared to 4.0.3
However, this question is still open. Does anyone knows how to speed it up?
---- Here is some updates ----
The minimal code is just simple, in the seekbar callback I made
imageViewB.setAlpha(selectedAlphaValue);
The VERY slow means the fps is less than 1~2. I do hope I can get the alpha changed 10 times a second to make users feel comfortable. (BTW, I don't benchmark the delay of set alpha function because it is TOO SLOW, even my human eyes can notice it only changes 1~2 times per second)

Thanks Nikola,
ViewCompat.setLayerType(view, LAYER_TYPE_HARDWARE, null)
Is the right thing to do. It solve my problem like a charm.
Could you please post your reply as an answer, Nikola? So I can rate you as the correct answer.

Related

Unity buttons sometimes black out in Android

I recently started developing in Unity and I like it a lot so far, but there is this one bug, I can't tell where it comes from and similar reports of others I read didn't help me.
The problem is that buttons sometimes (almost always by now, not so often in earlier versions of my project) are straight up black and have very dark grey text in them, which is completely different from how they are supposed to look like.
Even if I put all buttons of the color to straight white, this happens - only in Android btw! (Not tested in iOS, but it's neither happening in the editor, nor in desktop builds.
As I said, this seems to happen more often, now that the game got bigger, has more buttons etc. - so I would guess that is has something to do with setting the Source Image of those buttons to UISprite. Also this does not happen to buttons that have an actual image as Source Image, not the default UISprite.
So this is an example of how it is supposed to look like
And this is how it actually looks like:
Has someone got an idea? I assume it is something about loading the UISprite.
According to your comment, the correct answer was what I thought (see my comment).
Too big textures are hardly supported by Android devices, because of the heavy memory consumption. Scaling down all textures should solve the problem. You can also simply add a lower scale of the texture and switch it before rendering if the device is a mobile. Add a script to your buttons and insert this :
public Image loweredSprite;
public Button button;
void Start() {
#if UNITY_ANDROID
button.image.overrideSprite(loweredSprite);
#endif
}

Creating a more responsive android notification

I am interested in what the current best practice for android API 16 is when it comes to changing a notification button.
Currently I set the bigContentView and use setOnClickPendingIntent() to make callbacks to the service but I'm finding the notification to be really slow at being updated as it has to change one of the button images between two different states (like toggling play/pause).
After logging ive traced it down to the code of swapping the drawable button.
setImageViewResource(viewId, srcId);
Takes anywhere from 1.0s - 0.3s which is a noticable delay for the user, surely there must be a better way? Or something I'm blatantly missing?
Any suggestions to avoid the update delay or any feedback on my current implementation would be greatly appreciated.
Load the two ImageViews above each other and switch the visibility between them. This way you will only need to load them once and you will avoid many Garbage Collection calls that could result in slow responsiveness in your app and you can also scale down your resources to a smaller size.

Avoid high overdraw and long View drawing

I have a problem with a BI application I'm writing.
The application uses AChartEngine for charts and most of the table data is inflated programmatically. There are currently two main problems I'm facing:
When the application switches orientation, it takes around 8-10 seconds to redraw every dashboard element (i.e. to display data). Is this a problem with overdraw or something else (this happens on N4, N5, Note 3...). This is unacceptable and I really need to fix this!
There's almost 4x overdraw on table row elements, and I managed to get it lower - to around 2-2.5x with getWindow().setBackgroundDrawable(null). How do I fix this much overdraw as everything is inflated from code? (here's an example of how it looks like: http://prntscr.com/2lio5q).
Regarding overdraw:
Have you checked Romain Guy's Android Performance Case Study:
http://www.curious-creature.org/docs/android-performance-case-study-1.html
You can also find several Google I_O Videos by him (some of them dated) that might be helpful.
I finally fixed the orientation working very slowly. I applied few flags to my FragmentActivity in the manifset and it works much better now, flags are android:configChanges="screenSize|orientation|keyboardHidden".
Keep in mind that for this kind of thing it is much better and Android-like to use the FragmentPagerAdapter than FragmentActivity, but I work with what I got.
Hope this helps someone!

Display ALT-219 █ in TextView on Android - Extended ASCII

I want to display a block character "ALT-219" in a TextView. It isn't easy to search Google or stackoverflow for this as block means so many other things but I tried. I experimented with saving the file as a UTF-8 and my entire project crashed in some unexplainable way, I went to backups, that crashed in even worse ways. I finally backed out of what I did and rebuilt so I am back to scratch but I am not inclined to experiment without asking for help.
What I am really trying to do is create a pseudo graphic meter so that I have different strings for different values like a gas gauge where there are different number of ALT-219 characters as the values change. This gives me a gauge 1/4 inch high on the screen that goes from one edge to the other and when the tank is empty, no ALT-219 and when full the entire line is full. Not really a gas gauge but I am just trying to explain it.
String ascii="\u2588";
quoteText.setText(ascii);
I did this way and it is working perfectly fine no crash.
Thanks :)

Problem in Android Game using AndEngine

Hey all,
I am having an unusual problem with my Game. I am loading six textures in my Game, the initial one is a type of Game Background. Now at click of a Sprite i load a Dialog with infalted XML. The problem occurs here, when it first loads my game Background becomes black, when it reloads again it returns to it's original, when it reloads again it's black and it continues like this. It's a big code and that's why i cannot post it here, may be any one of you help me in this. I am stuck since many days in this, I have not unloaded any Texture, but still it's looking like that...............
Hope to get some help from you all..................
Thanks............
Try copying your game to another project and keep removing stuff to narrow down the problem until you don't have the problem anymore. I'd start with removing textures.
How many textures of what size do you have?
This is my raw guess.
you could have kept the Dialog's inflated xml root layer's(linearlayout) height and width as fill_parent. This could have occupied the entire screen and let things black.
make it as wrap_content to both.
1024x600 Textures are impossible! Both dimensions have to be a power of two, AndEngine does not accept other dimensions as many (all?) devices would not allow this.
Sorry but my time is currently very limited (due to exams =( ).
kkkkk SO it's a very delayed answer but still, may be it may help others. I exactly don't know what the problem was but after removing a texture, making size of some other's small, and also when android got updated, the problem is now very delayed, or it rarely comes.
So as per what i can think there seems only two issues, some memory prob or some bug in android which resolved with new update.

Categories

Resources