I am very new to Android development and am having some trouble. I am creating an XML file using Eclipse, both the Graphical Layout feature is what I'm having trouble with.
Also, I am working in Android 2.3 for compatibility reasons.
I am wondering if there is a layout which enables me to place buttons or text fields or any attribute where I want to put them. This may sound stupid, but it seems that every layout has some sort of order in which it lets you add attributes, and whenever I try to drag them elsewhere on the layout things just get very very messy.
If what you want is an AbsoluteLayout, this has been deprecated since Android 2 (IIRC). You can try using the RelativeLayout, which let you position freely your widgets. Else, if you only use LinearLayout, then yes the widget will be positioned in a strict way.
use Relative Layout. I recommend that you read up on Android layouts so you understand why, what and hows of Android way. There are some good tutorials that I found helpful. TutsPlus: Android Layouts
There is also a very good video from Marakana.
Marakana: Android Bootcamp
If you are just starting out with Android check other tutorials/videos on Marakana. They are a very good resource for beginners.
Related
I'm just starting to learn how to develop Android apps and when I tried to finally test an app with the emulator, the TextView, ImageView, and Button controls all seem to be stacked on top of each other at the top of the screen. I formatted the controls with the simple drag and drop feature in Android Studio. How do I fix this?
Tool you are using is called Layout Editor which is not so great for building layouts actually.
That drag-n-drop creation can cause errors like that and you should probably start from here or here
Hint: as a parent layout you most probably (in this case) use LinearLayout with vertical orientation.
Good luck!
The best practice for you is to try to follow a tutorial or a course to get a better understand of how the user-interface works in android.
That's might be useful Android Basics: User-interface
Good luck!
My question is about the ConstraintLayout because since Android Studio 2.3, when I want to create a new Layout, the default Layout in my xml file is the ConstraintLayout.
Is the ConstraintLayout the new standard ?
What about the others layouts (LinearLayout, GridLayout, RelativeLayout,...) ? Will they be depreciated ? Do I have to Convert all my layout using the converting tool ?
What is the best practice? Use as much as possible the ConstraintLayout ?
This is a bit confusing because I don't like to use the visual editor and it's a quite difficult to do ConstraintLayout using the code editor.
when I want to create a new Layout, the default Layout in my xml file is the ConstraintLayout
Whether or not a ConstraintLayout is created depends entirely on what templates you are using.
Is the ConstraintLayout the new standard ?
It is what many of the Android Studio 2.3 templates use. Those templates are merely examples used a starting point by some developers. Those templates differ on older versions of Android Studio and most likely will change again in the future.
What about the others layouts (LinearLayout, GridLayout, RelativeLayout,...) ? Will they be depreciated ?
That is very unlikely.
Do I have to Convert all my layout using the converting tool ?
No.
What is the best practice? Use as much as possible the ConstraintLayout ?
Use what works for you. Consider ConstraintLayout as a candidate, but do not feel obligated to use it. In particular places where you determine that layout performance is critical (e.g., scrolling lists), if you determine that your existing approach is not performing well, consider testing ConstraintLayout to see if it helps (it may or it may not). Also note that ConstraintLayout itself does not handle all scenarios — for example, I have yet to see a working means of implementing a TableLayout structure (with automatic column sizing) using a ConstraintLayout.
I have used localization in my android application. Which supports two kind of layout in application.
I have used Fragment and Fragment Activity in my application.
If language is English then layout should be aligned to left as shown in image below.
And if language is Hebrew then layout should be aligned to right as shown in image below.
I am trying to load this layout by two different layout files and then I can detect which language and I can use appropriately.
Is there any other good methodology through I can use achieve this functionality without creating different XMLs for all layouts?
Can anybody please help me to resolve this issue?
This should help:
http://developer.android.com/about/versions/android-4.2.html#RTL
Android supports right-to-left layouts natively since android 4.2.
Creating two similar layouts those are having same #+id values is a clean approach but if you don't want to create two different layouts then you could simply set the layout_gravity attribute by code with some helper method and by getting the LayoutParams of the containers you are using in your xmls.
Edit :
From another answer , If it works for you with the support package i.e. v4 if you are targeting 2.2+ above then this would be an awesome approach to go with.
http://developer.android.com/about/versions/android-4.2.html#RTL
just came to know about this. Android is awesome!!
I have know core java, I want to develop android apps, in few sites I saw apps in XML in few Java.Which is best and easy to use Java or XML?
I'm assuming you are talking about the UI, not the complete app:
For everything statically I use XML, because it is easy to find in the structure of your project.
Some parts you want to create dynamically and you have no other choice then to use Code. Be smart, in this, so if you have to add several Views that look the same do this
Make an XML with your views
In the loop where you are adding the several Views, inflate this xml, set your id's etc, and add them
You can have all the basics, styles etc in your XML, and still add stuff dynamically.
Maybe you want to check out some of the hello world code?
You can't build apps in XML. You use XML to define the UI and a few other things, but the logic of the app itself has to be written in Java.
Android development is in Java, but when you declare the layouts (where the buttons and so are going to be on the screen) you do that in XML.
So you have to use BOTH anyways.
XML for layout
JAVA for programming your app
I'm using Relative layout for designing UI. Please give me guidelines to follow.
Hey, You can use Layouts according to the requirement that will depends on your application.
If you want to display the UI in table format then use TableLayout
If you want to display that line by line than use LinearLayout
like that you have to select the layout
Note: You can use multiple Layouts in the single Xml file that is in LinearLayout you can use tablelayout if required
You will find lots of tutorials here: https://developer.android.com/guide/practices/ui_guidelines/index.html.
Relative Layout
Hmm, I'd suggest looking at JQTouch ( http://sencha.com) which is aimed at web-kit browsers, including iPhone and Android. It has APIs to help you with layout and various transitions. Seems to work well in Dolphin although I have not tried it on the iPhone.