I am trying to implement the minimumfontsize property in android. This is common to the ios sdk. Since it is not presently available in android I was wondering if anyone can help me with a similar implementation in android?
To be more specific, I am trying to implement this property for the TextViewUI in android.Hence I basically need to implement it for this widget.
These are the ios specs of this feature:
"When drawing text that might not fit within the bounding rectangle of the label, you can use this property to prevent the receiver from reducing the font size to the point where it is no longer legible.
The default value for this property is 0.0. If you enable font adjustment for the label, you should always increase this value. This property is effective only when the numberOfLines property is set to 1."
Without knowing what you intend to do with the code, there isn't much help to be had. The closest thing to what you describe in android is setting device independent pixels (android:textSize="30dp"), which ensure that however big (or small) the text looks on your handset, it will look pretty much just like that on all other handsets, at least those of the same size/density. See R.attr and Supporting Multiple Screens
Related
I work with FireMonkey in C++Builder, and I'm trying to make a transparent form, so that the components that are on it are displayed, but in the space where there are no components you can see what is below the form (transparent)...
I have set the Transparency property of the form to true, but the areas of the form that should be transparent look BLACK.
I have searched the Internet and found solutions for Delphi, but none for C++.
I tried to include this in the manifest:
SetActivityAttribute(MYFormTransparent ,android:theme, #android:style/Theme.Translucent.NoTitleBar)
but still, the same issue.
Any ideas?
This is a known problem that was introduced in 10.3 Rio. It has already been reported to Embarcadero (unfortunately, it has been closed as "works as expected"):
RSP-22314: Transparency Property
Marco Cantu commented on that report:
Sorry for not commenting sooner. We have done some research on it for the last update, but decided to defer a fix.
The core issue (in short) is that we use Android SurfaceView and this is a limitation of that platform control (only 2 SurfaceView instances are available). We are using this platform element as it allows us to mix styled and platforms controls (a feature we introduced in 10.30). By chancing the internal implementation, the transparency become unavailable.
There is an alternative implementation of forms via TextureView, but so far our tests have shown that the speed of rendering 2 times slower, and we don't want to slow down all FMX applications on Android for this feature.
There are some workarounds, one of them is to use a frame instead of a form. It works perfectly with transparency and uses less resources than separate form.
For existing code the fast way is to add a Layout to the form and have the controls inside it. When you need to display the form with transparency you can just move Layout from the specific form to main form as a child and align it on content Align = Content.
Other commenters noted:
I tested an alternative with formStyle = popup and stylelookup = popupboxstyle
with a rectangle in the form with transparency = 0.4 and some instructions to size the form with setBounds
The result is acceptable
As said by Herve Escriou, a work around is to set your formstyle property of the form to "Popup". This will make the form transparent again. But this wil have the effect of the wsMaximized style not working properly. You can go around this by making the following code additions to your form: ...
I have looked for question on this website and through google but there are no easy ways to set the size of the a View proportional to the parent.
Since android is a language that runs on devices of many screen densities and sizes it would make sense to have an easy to use method to set the size of views based upon the parent such as: 0.5*match_parent
I found some solutions but none of them are simple single lines that you would expect would be built into android, since every android app needs to support many screen sizes.
Is there some restriction because of the way activities are built? Is it inefficient to have to retrieve the size of the parent?
Now it is possible to set size proportional to parent. The Constraint Layout
allows to do it.
Check this answer for more details
Is there any way to change the layout of your app based on what text size the phone is set to? I know you can set your text so it will be static (stay the same size) but I've had some users complain because the app doesn't look good because of the large text. These are mainly older people who need the large text and it would be nice if there was an easy way to accomplish this without splitting one activity into two separate ones so they could still use it. Any ideas?
I was working with Android UI in Eclipse and found it to be bit hectic. Designing layout using layout managers is bit time consuming. So i was wondering whether it is possible to specify the position of the UI elements based on (x,y) system i.e top and left property which is widely used in Visual Studio IDE for VB,C# etc ?
Positioning element based on top and left property would provide much flexibility.
How would that be flexible? Yes, doing layout correctly takes time, but if you do it right, it will scale properly to any screen size. If you're using X/Y coordinates, you will be hardcoding to a specific screen size, which is an especially bad idea on Android (as there are a multitude of screen sizes available).
If you need x, y positioning, you can use a FrameLayout with foregroundGravity set to top|left, and use layout_marginLeft for the x value, and layout_marginTop for the y value.
You can use AbsoluteLayout and suppress deprecation warnings in your code, but think of how will it look on different screen sizes?
I would advise to use RelativeLayout in your case.
As far as I know, there is no built-in layout that is based on (x, y) coordinates. You might be able to find 3rd party libraries that can do this for you. However, I'm skeptical that they will provide satisfactory results. Remember that Android is deployed on a wide variety of devices which include a range of different screen sizes and resolutions. This means that you can make the UI look pretty on one device using specific coordinates but it won't look very good on other devices.
Personally, I edit my UI layouts directly in the XML files. I find that this provides me better control than using the Eclipse UI editor. You still have to learn how the layout managers themselves work.
Android tries to ensure that your layout components are arranged nicely so that they:
don't overlap with each other
don't go off the screen space
look similar on different screen sizes
etc
It gives you nice XML Attributes to help you arrange your layout. I would recommend you use RelativeLayout for this application, because it allows you to put your layout components in positions RELATIVE to each other.
Some XML attributes you can specify are given here: Android Reference, RelativeLayout.LayoutParams
I am having trouble in creating generic layouts for my application. As expected, it can be used in a variety of devices and I want it to work properly for each of them. There are several approaches to achieve this problem but I want to create an xml file (similar like web.config files) and at the very beginning of my application I want to take the device's screen width and height and calculate each control's (textview, spinner, button etc.) attributes (such as margin, padding,width, height...) according to this width and height and save these calculated values into my xml file. Finally I want to reach these values from my layout xmls so my layout's visual will be independent from the device and will work properly for each device. Can this be achieved? I could not find any similar solution on the internet. Can anyone help me?
Thanks in advance.
You can do most of this without hard coding values using RelativeLayout and similar mechanisms. The two pass dynamic layout system is made for exactly what you're describing.
However, when you need to be more specific, that's where the dynamic resource system can help you out. For everything you define in res/drawable, res/layout, res/values, etc, you can define specific implementations for device orientation, pixel densities, screen size or even language by qualifying sibling directories with the correct format. Provide a resource with the same name in different folders, and the system will decide which to use based on the runtime environment.
Give this a look:
http://developer.android.com/guide/topics/resources/providing-resources.html
I would not use custom measurements to dynamically set layout parameters. Android specifically has a variety of functionality to address this for you (including supplying multiple image resources, or layouts specific to a screen size).
I have discovered that the more you try to customize the Android layout with hard-coded values (always use DP if you do want to set specific parameters).
Bottom line, you should not try to re-invent the wheel, and just use the well-designed functionality that Android has already built-in to accomplish what you want.