Android TextView appears blurry when scaled - android

I recently found out that TextViews on Android are shown blurry / fuzzy when they are scaled in the 1.0-1.49 range.
I am not sure why this is happening, but it looks like a raster version of the unscaled version is used when the view is scaled on the XY axis in this range. However, the problem disappears if the view is scaled with a value above 1.5 (150%). Please check the attached screenshot collage in full resolution: https://i.imgur.com/A31ZC1N.png
The attached screenshots are from a real device, running Android 7.1.2 (API Level 25).
I have also tested this on an emulator running Android 9 (API Level 28), the results are identical. However, on my other device (OnePlus 6, Android 9), this issue is not present, everything scales nicely, without fuzziness.
A workaround for me was disabling HW acceleration on the current activity:
<activity android:hardwareAccelerated="false" />
Another workaround was setting a software layer on the parent of the view that is being scaled:
((View) mScaleValueTextView.getParent()).setLayerType(View.LAYER_TYPE_SOFTWARE, null);
Both of these will result in the TextView being scaled without the mentioned issue, but these methods have drawbacks, the first one that I noticed was that TextView's shadow caused by the elevation property was not drawn.
In order to demonstrate the default behavior, I created sample app where I added a TextView and a SeekBar that controls the scale, ranging from 100% to 200%.
The view is scaled by this method:
private void scaleView(View v, float scaleValue) {
v.setScaleX(scaleValue);
v.setScaleY(scaleValue);
}
You can get the entire sample app here.
Since the same code behaves differently across devices and the issue is occurring just between the mentioned scale range, I assume this is the result of a lower-level performance optimization that may or may not be implemented on some devices.
Is there any way to disable or work around this in a clean manner, without unwanted side effects?

Related

Can't Center the scene to the screen in Godot?

I have few scenes in my project. I was able to center all of the other scenes. But i cannot center the main scene in my project. Its fine when it opened on a mobile device(probably because resolution matches i guess). but when i opened it in tablet(its an old tab "xiaomi tab 3") its always align to the right on the screen. I was able to center other scenes but i cant center the main scene to screen for some reason. project setting set as 2D and Expand. I also tried to use Control nod, canves layers, margine containers.. but nothing works. If someone can give any suggestions, Thank you in advance.
img1
https://i.stack.imgur.com/FJOHl.jpg
project
1920 x 1080
I have seen this problem, or similar, in windowed mode. I don't know if this is the exact case, but if it doesn't mess with your project, try full-screen mode.
If it's that, you can also take care of the window bar size (which is a problem because it can change from different devices), since godot will count its pixels too.
Notice that you're only having this problem in one axis.
Also, I think you could take a look into the Viewport Stretch Mode. It could mess your graphics depending of the intended result—but other projects won't even notice, so judge for yourself.
The viewport setting sets the root scene’s Viewport to the base resolution. The rendered output of the root Viewport is then scaled to the display resolution. [...]
The viewport setting is a better choice than the 2d setting when pixel-perfect precision is required, since primary rendering still occurs at the base resolution.
Support multiple devices
Scaling correctly for all devices could be an odyssey, so bon voyage.

Full screen preview Android camera2 [duplicate]

I'm trying to modify Google's camera2Basic example code. I removed the <FrameLayout/> containing the "Picture" and "Info" button in an attempt to make the <TextureView/> full screen. However, the preview does not fill the entire screen, there remains a black bar below it. I believe this has something to do with the AutoFitTextureView that it ships with but since they haven't provided any documentation on how it works I am unable to make modifications to it.
I noticed this exact same issue before on my Galaxy Note 5 and I believe it had to do with the way they set the aspect ratio - there are apparently some limitations with this API (or just poorly documented). I fixed it by not setting the aspect ratio on the AutoFitTextureView.
Specifically in this example, in the method setCameraOutput(int width, int height), simply remove these lines of code (lines 574 - 580 in your example):
if (orientation == Configuration.ORIENTATION_LANDSCAPE) {
mTextureView.setAspectRatio(mPreviewSize.getWidth(),mPreviewSize.getHeight());
} else {
mTextureView.setAspectRatio(mPreviewSize.getHeight(),mPreviewSize.getWidth());
}
I believe that in the example they are trying to limit the capture area which likely leads to the black bar you are seeing (probably because you are building on a larger device than the one the person who developed used).

TextButton padding changing with Android version

I have been developing an app over the past few months getting ready for publication. Everything was looking just perfect. I was doing a few things with text in buttons - using my own 9-patch button backgrounds, changing the default font, repositioning textbuttons with setX() and setY() etc. I had some big buttons and smaller ones. Some were a tight fit amongst other objects on the screen, but it all worked, the buttons looked perfect on a variety of tablets and phones.
Then I remembered one last thing on my todo list which wast to change the android:minSdkVersion in my manifest from 8 up to 11. I needed to do this because the setX and setY methods are only available on android 3.0 and higher. But as soon as I did this, the text within my buttons was all screwed up. For a start it was white instead of black - easily fixed. But also the padding round the text was completely different. Buttons were now overlapping each other and looking unbalanced in a variety of ways.
So my question now is this: Is there any way to say "this software must only run on Android 3.0 (api 11) and above" AND "let all the text button characteristics be set to whatever that were with api level 8".
I have no idea why such things would happen - but it's better to just support the older platforms if you can help it. For example, if the only thing keeping you from using API 8+ is the setX() and setY() methods, you can use ViewHelper in the NineOldAndroids project to do this and support the lower API. For example:
ViewHelper.setX(myView, myXValue);
ViewHelper.setY(myView, myYValue);

Auto Scale TextView Text to Fit within Bounds in 4.0

The solution Chase gave for this problem was working fine in 2.2 - 3.2 but when I tested it on 4.0 it failed.
Here is the original post:
Auto Scale TextView Text to Fit within Bounds
On 4.0 I get a strange line spacing problem which brings me to something he/she wrote in his/her code:
// Some devices try to auto adjust line spacing, so force default line spacing
// and invalidate the layout as a side effect
textPaint.setTextSize(targetTextSize);
setLineSpacing(mSpacingAdd, mSpacingMult);
I guess this is failing now and I'm not sure why (anyone?). Also not sure why he/she wrote it in the first place as isn't this OS dependent and not a device dependent problem?
ICS has TextView resizing issue where in some conditions it will resize up but not down. This black magic works for me. After you set the text of your TextView, also perform this
textView.append("\uFEFF");

Sideways View with XML Android

Is there a way to display a View, such as a TextView sideways using the XML layout file? I know you can rotate the view using code in an activity, but is there a way just to do it with layout?
There is, but it's new in API 11 (Android 3.0):
<TextView
android:id="#+id/rotated"
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:rotation="270"
android:textSize="32sp"
android:textColor="#44CC44"
android:text="#string/rotated" />
I tried this in 2.2, 2.3.1, and 2.3.3, and "android:rotation" wasn't legal.
It worked in 3.0 on the emulator, but it was odd. I also added paddingTop="90dp" to it (to get it away from another component in the test app I tried it in), and it not only moved down the screen, but also to the right (away from the top of the text, since it's rotated 270 degrees). I don't have an actual Honeycomb device to test on, but it looks like rotation and padding/margins might not play well together.
There is also an android.view.View#setRotation(double) method that has been added in API 11 which tweaks this property from code. And in addition to rotation, there is rotationX, rotationY, pivotX, pivotY, scaleX, scaleY, and translationX, translationY. I haven't played with any of them yet.
There is a list of all the changes in API 11.
But I suspect you wanted something that is not only limited to Honeycomb. As far as I know, there isn't.
David is right, the :rotation WILL work but something is messed up in the SDK I believe. The Graphical Layout will cause the text to move far left or right (and possible off screen) so it BUT when I run it on my Xoom, it works as expected. So try the settings on an API 11 device to see it's affect.
Also, It looks as if it does something with the width/height as well. The only way I can get it to work is to make the text view square. In other words, if you normally only needed a 100dp wide by 25dp high textview, make it 100dp x 100dp then rotate and try it. Also, top/bottom becomes left/right, etc when you rotate 90 degrees.
I can't figure out what RotationX/Y does. It seems to do nothing for me.

Categories

Resources