positioning items in android dev - android

Hi
I'm totaly new to android,
I'm looking for a very very very simple thing that in every possible dev env is straight forward, except apparently android.
how the hell do I set X and Y for every UI object that I wanna place there.
For example in xml i have LinearView or RelativeView and in them I have Button, I'm looking for a way to set this button position on the screen using Y and Y, should be pretty straight forward thingy, I mean in iOS dev you just do CGRectMake(x,y,width,height) and there you go.
What is the equivalent in android dev?
thanks

From Android Developers
Android is designed to run on a
variety of devices that offer a range
of screen sizes and resolutions
So, unless you are targeting only one specific Android device, you'd not want to use absolute coordinates, as, for exemple, x=300px on one device can mean a reference outside the screen on another device(a small-screen one).
Instead, you learn to use just relative positions as top, bottom, below, etc, that works on every device.
Try to do the Hello Views tutorials first, in order to better understand how things are working for Android.

Please use layout_x and layout_y with a AbsoluteLayout in your layout xml.

Related

Need approach for screen development in android

I need expertise advice/approach for starting screen development in android.
I got a couple of screens from my customer and i need to develop them.
I went through lot of tutorials and understood about supporting multiple resolutions and sizes all that is fine, but i want to understand basic things like how to properly place the UI elements. Should we need to use any tools like photoshop for measuring units like top bottom right left etc and place the UI element in xml or just by approxiamtion we will place the UI element.
For example consider this screen https://d13yacurqjgara.cloudfront.net/users/137442/screenshots/1234960/attachments/166804/Login-screen.png.
for ex How you will place the user name and password edit texts. I mean how much of top left bottom margins will be used. is that just approximation or need to be measured using tools like photoshop.
Say i used photoshop and got the values in pixes if i convert them to dp and use those values in layout will they support for other screen sizes??
are there any tools which can take the screen iamge which i posted above as an input and generate the android layout from it.
You don't need Photoshop to measure the units. The Android SDK has several layouts with their accompanying properties and options that will allow you to pretty much achieve any UI implementation. imho there are not tools that will 'take a screen image and generate the android layout from it'.

what is the iOS equivalence of Android RelativeLayout/LinearLayout?

How do I control the relative position of views, especially I wish my app to run on 3.5 inch display and 4 inch display seamlessly?
As of iOS 9 you can use UIStackView, which works very similarly to LinearLayout: you add views and the stack view arranges them as needed based on your sizing option – if you're using Interface Builder you can experiment with each of the options to see which one suits your needs. You can also set spacing between views in the stack view, adding some padding.
WARNING: When adding stack view child views in code you should always use addArrangedSubview() like this:
stackView.addArrangedSubview(someView)
If you try to use plain old addSubview() it won't work correctly, because the stack view won't know to arrange it.
As for removing, you need to be careful to use stackView.removeArrangedSubview(someView) and someView.removeFromSuperview() otherwise the view won't be removed correctly.
You might find my UIStackView tutorial useful.
There is no equivalent or relative and linear layouts. The UI elements have autoresizing masks which define how will they be moved/stretched when their superview is resized (e.g. screen rotation). You can also use layout constraints for positioning if you intend to build your app for iOS 6+. If you can't solve the repositioning using these tools, you should change the frames of the UI elements in your code.
Check out this: iOS 6 apps - how to deal with iPhone 5 screen size? and How to add iPhone 5 large screen support to iOS apps in Xcode?
But it's done for you for the most part with auto layout. Click on your project in Xcode and go to the Summary tab to add the different screen size launch screen for your app.
Auto-Layout system ≫ RelativeLayout
UIStackView ≈ LinearLayout
IMO. UIStackView was not well designed
can't easily add extra constraints between subviews/subview and superview
it's too often to produce conflicts of constraints
x. iOS 9+ only
So i wrote AutoLinearLayoutView, a replacement of UIStackView.
Demo screenshot
Checkout from Github AutoLinearLayoutView

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

Issues designing Android UI in Xamarin

I am in the process of writing my first android app. I figured, for a simple exercise, I'd write an app to keep score in bowling.
I want to create a picture of the pins, with a touch toggling a pin between standing, and fallen. Then an ok button, that completes the shot. After each shot is entered, have a picture of the score updated.
Then, I want to be able to click on a frame, and edit it...mistakes happen.
This seemed simple enough. At least if I were to whip up something in HTML5 I would be done by now.
However, I'm struggling with just drawing the UI...ugh.
Would I just create the pins as image buttons? And how do I align them properly...I can't seem to drag stuff where I want, it's all left aligned and stacked. Nothing like it should look.
And how can I dynamically create images for buttons? At least that's how I was thinking I would do the score (showing all 10 frames with the shots and running score.
I realize this is a beginner question. But I've been at it for five hours, and I'm no farther along.
I don't think it's necessarily fair to compare your speed in a dev environment you are new to with one you already know - you are bound to be slower in the new one.
To get more familiar with android's XML layouts, I recommend you take a look through some of the tutorials on layouts - on linearlayout, gridlayout, relativelayout, etc which I think will have you quickly working in XML to generate your ui.
One such tutorial is http://slodge.blogspot.co.uk/2013/01/an-mono-for-android-wrappanelflowlayout.html
Once you've learnt a bit about the XML, I suspect you'll also find the designer easier too.
For the questions about the pins, well these sound a lot like checkboxes, only drawn differently - so check out:
Custom checkbox image android
http://vimaltuts.com/android-tutorial-for-beginners/android-custom-checkbox

Android Text Placement

I am relatively new to Android development, and am developing an application with an image for a background. I need the ability to have text reliably and precisely placed in relation to certain points on the background image. I developed the application debugging on a Droid Charge. Everything looks fine there. However, I downloaded the application to a Droid X, and the text is a little off. I imagine I am missing some fundamental understanding about Android development, and would appreciate any help. Also, I believe this person is having a similar problem.
Screen sizes and precise element placement on Android
Well you need to understand that due to support of multiple screen, it's not wise to have a certain points or coordinates to draw your Views. If you want to draw a text according to a background position, then may be you should use a custom View where the background picture can work as the Background of your custom view and then you can place the text at the exact location.
Another idea would be to use a 9 patch drawable which is not stretchable (Background uses 9 patch drawable which stretches on changing the size of the view). However you have to supply different drawable for different screen densities then. I'd choose the first option, as it's easier.
PS: Tell me in comment, if you find any difficulty on applying any of the option.

Categories

Resources