Is there something like Android's match parent in Delphi? - android

I want to have components in my android app that will match their parent's size, but I can't find it in the object inspector.
If I use align and anchors it works almost similar, but it's still not as good as android's design.

The easiest way is to use Align property.
If you want your child control to fill the parent's entire client area, set the Align to Client. Note this one does not cover the parent control's borders. You probably know about this one from VCL where it was named alClient.
If you want your child control to cover the entire parent control, including its borders and such, set Align to Contents. This one is a new option that was introduced to FMX and is not available in VCL.
You can read more about Align options in the oficial documentation:
FMX.Controls.TControl.Align
FMX.Types.TAlignLayout

Related

Responsive Layout in XML

Which is the best option to create a responsive layout design? The first question is what should be the height and width of every view (it should be in percentage, match constraint or wrap content using constraint layout).
If we use wrap content I think there is no way to create a responsive design with help of wrap content because if content increase the view will take all the space of the screen either vertically or horizontally
If we use match constraint then, in that case, it's good, but sometimes it is looking awesome on Android Studio but when we run it on a real device it doesn't look the same
The last option is to use percentage, in that case, I think first we have to check our item list vertically and horizontally and provide them space according to their content priority and usage
So what will be the best case to create a responsive layout in XML for Android?
It depends on UI.generaly people use the 2nd and 3rd methods because by using constraints and percentages you can get responsive UI.
sometimes it depends on your requirement.
if you are using the percentage method and you set the imageView at 10 % it's looking proper on your device but sometimes it happened that in a small device that imageView is not looked proper
So the moral is all your three methods can be applied as per UI you can not make all designs responsive using 1 method

Controlling the positions of a views in Android

I am trying to create an android app where I have a single relatively big button in the middle (the light blue in the picture) and it is surrounded by other smaller buttons as shown in the picture (some of small buttons might be visible or invisible based on some criteria).
I started with the RelativLayout setting the big on in the center and making the rest placed in relation to it, but it is a miss and the central button get shifted and doesn't stay in the center. I tried placing them in FrameLayout and used margin to adjust their locations, that worked the best however, the spacing changes on different screen resolutions.
So what is the best way to achieve such layout that will look consistent on any device?
Android's Percent Support Library allows you to use proportions to lay out your views, which may allow you to get closer to your goal.
http://developer.android.com/tools/support-library/features.html#percent

Android UI based on top and left property

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

how to make multiple overlapped layout in android(it means make one layout disable and other layout become overlapped)

How to make multiple overlapped layout in android( for example I try to make two layout and make one layout to disable and other layout to enable for some operation, this layout overlapped with other layout).
You have a few options:
FrameLayout
This allows you to stack views directly on top of each other. This is nice and simple for some cases, but is limited. It will not help you align those views, simply stack them.
RelativeLayout
This is probably the best option, it allows stacking views on top of each other, but also allows for aligning views with each other. You can align edge, place views next to each other, or center in the parent. This is one of the most powerful views in Android.
AbsoluteLayout
This is deprecated and its use is discouraged. That having been said, this gives you pixel perfect view alignment if you know what the exact pixels should be. The reason it is deprecated is because Android devices have variable screen sizes and pixel densities, so more than likely when using this view you will be limiting your device support greatly.

Android SDK, Placeing widgets/buttons etc at will?

Hey Im new to android developing and I have a quick question. Is there a way to place buttons where I want them on the view? Right now they only seem to be placed where there is specific spots for them. Why cant i drag and place them where ever I want like in the iphone sdk for example?
Is there a way to do so or does this functionality not exist? thanks.
Android (eg. similar to Qt) uses a concept of layouts. This is especially useful when you're creating UIs that can be displayed on different devices with different DPIs, different screen resolutions, etc.
So instead placing your buttons at pixel coordinates you put them, independent of device screen resolution, into layouts.
Read more in User Interface documentation. Using Eclipse ADT plugin you can visually create layouts. You can even embed one layout into other, creating eg. LinearLayout in RelativeLayout. This gives much more possibilities of creating screen scalable applications (one app on phone and tablet for example).
There is AbsoluteLayout, but that class is deprecated. The recommended strategy is to use a RelativeLayout (you can control the position of views by setting layout margins) or build your own custom layout class.
An android UI screen is build for various screen sizes , due to which you can not specify an exact location for the UI component .
Android instead uses the concepts of Layouts where each layout has a different behavior. Here are a few of them.
LinearLayout aligns all children in a single direction — vertically or horizontally, depending on how you define the orientation attribute
TableLayout positions its children into rows and columns
RelativeLayout , one of the most used layouts , lets child views specify their position relative to the parent view or to each other (specified by ID).
Android uses layouts to design the UI. For example, a vertical linear layout stacks one element on top of the other.
AbsoluteLayout is the most precise, but it's also harder to maintain and can get messy.
I recommend RelativeLayout. It positions UI elements relative to other elements.
If you don't really need that much precision, one more option is nesting layouts within layouts. But doing that too much gets messy and RelativeLayout becomes the better option.
A UI element's position is determined by the layout you choose. See this link.

Categories

Resources