If I do setAlpha(0.5f) on a few (image) views, my app gets horribly slow, at least on my Android 4.+ tablets.
If I remove the setAlpha calls, the app (scrolling and paging) works smoothly.
Is there an alternative/faster method for making my views semitransparent?
If you provide some code I can try to see what is wrong, there is no reason and explanation of slowing the app, there must be other thing in the code/project/layouts to make your app work slower
Try creating a custom view that calls Canvas.saveLayerAlpha() before drawing its children. Android 3.0+ versions there is a View.setAlpha() api..
Also you can create transparent or opaque background.Here is the link
http://zaman91.wordpress.com/2010/03/22/android-how-to-create-transparent-or-opeque-background/
Hope it helps.
Related
I have an app that has a minSdk of 15 and I'm working out all the bugs that came with the lollipop upgrade. Our software is very complex and it dynamically creates views using custom ViewGroups and then an array of elements that are explicitly sized and placed inside the group. I'm running into an issue where for example I'll have a ViewGroup and the first child object is a Button...this button is sized to fill the view (not clickable). The second child is a FrameLayout containing a single view. This single view is a video object. In all prior versions of Android this works just fine. The FrameLayout is layered over the button (that is acting as a background) and the video is inside the framelayout. You can interact with the video without any issues.
Something changed in lollipop - suddenly, even though the button is showing up as the 0 index element, it is laying OVER the rest of the children...so I cannot get to the video underneath. If I remove that button element, the video renders and plays just fine...I have no issues interacting with it.
I ran the app in UI Automator Viewer just to make sure I was really setting up the UI as I expected (keep in mind the entire view is dynamically rendered at runtime using image/video assets and xml config files).
I'm not able to share code since this is proprietary software, but I am working on a little test project to see if I can manually recreate the issue with static objects. Once I get that up and running I'll be sure to update this ticket. For now, here is a screenshot of the hierarchy:
https://goo.gl/photos/a8on9CJDnN66XYnV6
Notice the highlighted object, this is the custom ViewGroup, the children below it are what I am describing above.
Does anyone know of a change in Lollipop that would effect the ordering of things? I found earlier that if you have a disabled object but don't have a disabled state drawable assigned to that object it would become invisible, previous versions just used one of the other state drawables..okay that makes sense and it was very easy to fix, but this object is not invisible...so it must be something different.
Any direction would be greatly appreciated.
~A
UPDATE -- FIXED
With the help of #alanv and #BladeCoder I figured out this functionality was due to the new elevation feature of Material design. I was able to fix my particular issue by first checking what version of android the device was using, and if lollipop, I just add this new property to the button:
android:stateListAnimator="#null"
This prevents my explicit child hierarchy from being overridden by the OS.
Lollipop introduced elevation as a way to position the elements on the Z axis and cast shadows between them depending on their difference of elevation.
Enabled buttons have a default elevation of 2dp (and it increases when you press them). So, your button has a higher elevation than the FrameLayout (0dp by default) so it will be drawn on top of it.
Disabled buttons have an elevation of 0dp. That's why disabling the button solved your issue.
Using buttons as backgrounds looks like a bad idea (why not setting a custom Drawable background on your FrameLayout instead?) but if you really need that, you can disable the button like you did and, just to be sure, enforce its elevation to 0dp. Another workaround is to increase the elevation of the FrameLayout but then it may cast a big shadow under Lollipop if it has a background, and maybe that's not what you want.
Okay, UPDATE! I figured out how to fix the issue, although I'm still not sure (even after pouring over the diffs between several classes in grepcode) what changed in lollipop that is causing a change in how this works.
If the button is enabled...and you are placing it using something equivalent to AbsoluteLayout (We have our own ViewGroup we created called Explicit layout, but it does pretty much the same thing as AbsoluteLayout), it will always be on top of anything else in the stack that isn't also a button of some sort (at least that's what I'm finding...I didn't test through every possible widget).
Setting the button that is acting purely as a background image to enabled=false solves this issue. I know, it doesn't make sense that we use Buttons as background images, but our code uses it for dynamic element creation so there are many possible states and uses for each element.
Anyway, not sure if anyone else would even run into this issue, but just in case you do...here it is.
Thanks!
I've just started to rebuild my app for Android 5.0, using the appcompat support library. I've just finished implementing a transition featuring shared elements. It seems to work well, untill I add a webview.
I've made a video to demonstrate the glitch.
https://www.youtube.com/watch?v=MuuGZc0Vwow
As you can see, all's fine when I open the activity. When I close it, the glitch occurs. As you can see all elements fade out like they should, except for the webview. Which just hangs there until the animation is over, kinda ruining the entire smoothness of the animation.
How do I fix this? If it could be related to the way I've set things up I'd be happy to share some code.
Thanks in advance.
The reason why this glitch occurs is because WebView extends AbsoluteLayout. By default ViewGroups that are not "transition group"s and that have no background drawable will not be animated by the activity's window content transition. In order to fix the glitch with the WebView, you will need to call webView.setTransitionGroup(true) (or set the attribute in XML using android:transitionGroup="true"). This should cause the WebView to fade away as part of the activity transition instead of simply sitting there until being abruptly removed at the end of the transition.
As for the "Unable to create layer for WebView" error you are receiving, I imagine that is because the transition framework automatically creates a hardware layer for the WebView during the transition and for some reason the framework is crashing when it is trying to create the layer. This sounds like a totally separate issue related to Android's internal graphic pipeline though... I'm not sure I can give you a good answer about why the crash occurs without more information.
This issue is also discussed in the bottom of this blog post.
I have facing exactly this kind of random crash problem in webview in Marshmallow version. I have add attribute android:transitionGroup="true". but crash is happening, after that i have added android:hardwareAccelerated="false" in manifest where that activity is declared. After that random crash has solved in Marshmallow version and lower version too.
I've been trying Rajawali to develop some apps, but, while it seems pretty good, I've ran into some trouble.
The main issue is that when i call a RajawaliActivity, and in every other activity called after it, the background of normal Android Views do not show, including the background of the layout being used.
As normal, I am using a RajawaliRenderer to show the 3d models, setting the surfaceView of the mRenderer, as shown in the sample apps and the tutorials.
Has anyone encountered the same problem or knows how to fix it?
In the manifest file set
android:hardwareAccelerated="false"
for each non 3D activity.
that solved the problem for me.
courtesy https://github.com/jwoolston
I'm using this library that allows flipping between views like the "FlipBoard" app.
It works quite well.
The problem is that I need to put a few views on top of it, so I've put it inside a FrameLayout, and the rest of the views after it.
It looks ok, but it has a problem:
When flipping, the views that are on top of it change their transparency (and even become hidden) till the flip is over.
How can I handle this problem?
EDIT: I've found this library which doesn't have this problem, but it has a weird color transition while flipping that I wish to avoid.
EDIT: I've found out that this is a known issue (#49) . Would love to know if anyone else has an idea of how to overcome this.
I don't know how to fix this library, but it seems this library works fine :
https://github.com/emilsjolander/android-FlipView
Not sure though how customizable it is compared to the one i've tested.
Is there an easy way to implement property animation(e.g. animate "x" or "y" property from value1 to value2) in android < 3.0? I need to animate a visual control(Button or TextView), that needs to handle click events(so, drawable animation is not appropriate).
Update:
So, there is a lot of games with animation(Cut the Rope, etc.). How these game developers solved the problem? What the way they use for animation?
I know this is an old thread, but for those who stumble across this in a Google search, there is a compatibility library available that gives you access to the property animations introduced with Honeycomb all the way back to Android 1.0.
I've used it for some small things, and it works like a charm. http://nineoldandroids.com/
Afaik, for this to work you have to roll your own animation framework first that interpolates the values the way you'd like. Then, you could animate e.g. the margin property of the button with this framework, calling .setLayout() on every tick. This causes the ui-framework to relayout/redraw the whole screen, with the new margin value.
However, this is a terribly slow and wasteful way to animate and I don't recommend it. There might be better solutions.