I use a linear background (xml shape) as the actionbar background in android 4.0. It does not display well, looks banded.
How to make it render smooth?
First, I'm assuming you're using the default RGBA_8888 pixel format (default as of Android 2.3). Second, on some displays gradients render poorly. One workaround is to overlay a small bit of noise over the gradient (a repeating semi-transparent noise texture in drawable-nodpi should do) using a <layer-list> drawable.
Try increasing PixelFormat quality of a window:
#Override
public void onAttachedToWindow() {
super.onAttachedToWindow();
getWindow().setFormat(PixelFormat.RGBA_8888);
}
This is possibly a duplicate of this question.
Is it a repeating pattern (tiled) or a nine patch?
ICS is having some issues with certain types of rendering since it is by default drawing using hardware acceleration which makes it impossible to use some drawing techniques (specially when Drawables) and generates undesired results with some others. You can see some explanation and a list here.
Fortunately there are solutions or workarounds to most of them. Just need to know which exact kind of element are you using to draw your background.
Related
On Wear OS in ambient mode, only black or white pixels should be displayed (no grays). Anti-aliasing a black and white image introduces gray pixels. Now, anti-alising can be disabled for a TextView by writing textView.paint.isAntiAlias = false (in Kotlin) but there doesn't seem to be an equivalent for vector images. The one thing I've tried is adding android:antialias="false" to the image XML file, but it seems to have no effect.
I don't think there is a way to do it in XML.
Personally I've only done this when drawing straight to a canvas. Setting setAntiAlias(false) (don't remember if we ended up using setDither(false) and setFilterBitmap(false) too) on the Paint did the trick.
You can try using a DrawableWrapper and make the necessary changes in the draw() method. Unfortunately this means that you have to set all your drawables in code, but at least you'll still be able to rely on an ImageView.
i'm using icons on recyclerview row items.And i'm changing icon's colors with Color Filter option in android but i'm wondering which one is faster and better?
different colored drawables
(run-time) color filter on white
drawable icon
I already use color filtering on white drawable but it sometimes does not appear in list row till refresh recyclerview so i just think about to use different drawables.
thank you for your interest...
It is hard to say, but I would say that changing the drawable is faster, and this is why I think this:
in order to filter a image the system has to read each pixel from RAM, transform each RGB component in order to add the tint (it's not as simple as adding +3 to the intensity of each pixel), and then write each pixel
changing the drawable implies reading from the flash memory and load it into ram
The thing is that flash storage on mobile devices is pretty fast too these days so I consider it's faster to load than tint images.
BUT it depends on how you create the layout. If you load a image the Android system will recalculate the whole layout if other elements change position when you change the drawable. I don't think they wrote code to keep the layout the same if the new drawable has the same size as the last one, and this will involve more calculations than a simple tinting.
color filtering is better because it use GPU( so it faster) and it can decries size of your final apk but sometime using hardware accelerator can make your application laggy and slow because of leak of memory ,size of your drawable, bad design and ...
I'm looking for way how to implement specific shadow (like on picture) in my android app Android, with using xml (I can't use 9 patch for this).
This is white rectangle with the same shadow in all directions.
Any idea?
As far as I know, there's no way to create a shadow efficiently with XML without using 9-patch image. You can try playing with shapes and gradients, but the result won't look good.
I also did some tests by adding several shapes with transparent borders, but again the result is not good.
Can you explain your situation (why can't you use 9-patch, which is well supported by android).
I come from an iOS background, where one of the rules for fast views is to avoid transparent backgrounds and pngs if possible. I haven't found any information about this on Android. So my question is, should I use non-transparent views and drawables where possible, or does Android not care about this as much as iOS does?
just like #blackbelt said, transparency always impacts on performance. When possible, avoid using transparent views and/or images.
Also, in Android you can have translucent views/activities. Those will impact performance a few orders of magnitude more than simple transparency. If possible, avoid those too.
You might want to check out the Android documentation regarding overdraw.
Unlike standard overdraw, in which the system completely hides
existing drawn pixels by drawing opaque pixels on top of them,
transparent objects require existing pixels to be drawn first, so that
the right blending equation can occur.
I have a transparent PNG image representing a bluetooth icon with a blue glow, exported from photoshop:
On a HTC Desire, a simple imageview is created, and the PNG is used as a bitmap.
If the background arround the imageview is white, there are differences between nuances. If the background is black, than the differences are hidden.
If I use ADB to do a screen capture, the problem is not visible:
Possible causes:
The screen uses a higher bit depth rate than what is used for the bitmap. Eg. RGB24 vs RGB16. By doing so, the screen has a wider number of nuances for white than what is possible for the bitmap encoding. When displayed, the bitmap's pixels are approximated to the new bit depth requirements, but fail to properly match the background nuance because of the approximations used. Eg. RGB16->RGB24 would mean C24 = 255*C16/31 .
If I use the screen capture software, the bit depths are probably downscaled to a narrower bit depth value (RGB16) so all the nuances merge together and are approximated to the simpler, 16bit colors. This is why I used a photo camera to illustrate the problem.
The Question is how to fix this?
I already tried loading the bitmap with parameters such as:
resample.inPreferredConfig = Config.ARGB_8888;
But to no use.
I simply need to display a transparent image, such as an icon with GFX effects: shadows, glows, etc. I would be happy to use a grayscale mask as well (Black=>White mask to indicate the pixel transparency, but didn't find a way for that either).
Thanks for your time!
You can just set the Window format before setting the contentView in an Activity.
getWindow().setFormat(PixelFormat.RGBA_8888);
This probably has nothing to do with bit depth.
The "whitish square" you described is in your screenshot as well. It is possible you can't see it on your computer monitor if your monitor is not properly calibrated.