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.
Related
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.
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?
I’ve used Fontastic.me to create an iconfont. It works great except in the native browser of Android 4.2.2 and 4.3 (eg: modern Samsung tablets).
In these browsers, the characters of the entire font have no width. This occurs with every font made with Fontastic.me (even the fonts it supplies itself). This is a major problem when centering the icons (horizontally).
I've set up a webpage to test it: http://ajuin2013.boondoggle.eu/fontastic-streamlineicons/icons-reference.html. The pink color shows the width of the character.
The following screenshot compares the normal behaviour with the AndroidBrowser-behaviour :
http://ajuin2013.boondoggle.eu/fontastic-streamlineicons/fontastic.png
I’m sure it’s because of the Fontastic, because when i use Icomoon as fontgenerator, the problem doesn’t occur. I've also notified the owner but he says he can't look into it because he doesn't now how to install an Android Emulator on his Mac.
Does anyone has a clue to what's happening here? What causes the character-space to collapse?
I had the same problem yesterday. I resolved it with a little bit of a work around. Like you said, when you want to center the icon with text-align:center; it ends up more to the right. If you put it to the left, it aligns left as intended. So I made the speudo element exactly the same width as the icon and centered the speudo element with margin: 0 auto; In that case you can leave the text-align to the left.
I know it's not the perfect solution, but for now it works for me and maybe also for you.
I had the same problem and resolved it by using icomoon.
In an app I'm developing, I need to layout 2 to 5 buttons as if on the edge of a circle. The app starts with 5 buttons, but buttons gradually disappear (based on user input) until there are 2 of them.
I thought I would use an AbsoluteLayout control, and set the position of each button in code (taking into account the screen size). However, it says more or less everywhere that AbsoluteLayout should not be used. Since I'm targeting this app to Android 2.2 and up, I can't use the fancier layouts introduced with ICS.
I know I can use a RelativeLayout and play with the margins, but this seems less intuitive, and just as error prone, as using AbsoluteLayout.
Do I have any reasonable alternative?
I think, you dont have many alternatives. Except relative layout you mentioned, you could of course use FrameLayout and set left and bottom margin to position your buttons correctly.
I have a fullscreen view which I partially move in and out from the phone screen, let's say to the half of the screen.
To do this I am using MarginLayoutParameters to set the top margin to half of the screen, or to 0 in case I want it to be fully visible.
Everything works perfect but now that I am testing on other phones, which seem to be the ones of low resolution, the view is correctly cut by half but is always aligned to the top.
Trying left and right margins also always aligns it to the left.
Am I missing something that newer phones/ Android OS already does for me?.
This view is inside a FrameLayout.
Thanks in advance.
Well I just used setPadding with the same results I wanted to achieve, but my question still remains.