I'm using frameLayout in my project.. but I totally confused in android developement about that if I use xml file for static approach whereas on other side I'm using java code for run time behaviour for frameLayout(or any android feature) which approach is good for my project as user-experience point of view.. please provide only your straight forward sight of view with reason.. thanx in advance.
-
1You can also take a look at the documentation on XML: https://developer.android.com/guide/topics/ui/declaring-layout.html. The topic is also discussed here a bit: http://stackoverflow.com/questions/13878053/android-xml-vs-java-layouts-performance. For general knowledge, FrameLayout is already the most efficient layout because the location of the components is statically declared and there is no calculation necessary on behalf of the OS to figure out where the components need to go. – sam_c Mar 28 '17 at 17:19
-
yep bro.. sam_c thanks. – sidVoter Apr 03 '17 at 20:35
2 Answers
it's something similiar to earliar asked question.
Declare UI elements in XML. Android provides a straightforward XML vocabulary that corresponds to the View classes and subclasses, such as those for widgets and layouts. Instantiate layout elements at runtime. Your application can create View and ViewGroup objects (and manipulate their properties) programmatically.
The advantage to declaring your UI in XML is that it enables you to better separate the
presentation of your application from the code that controls its behavior. Your UI descriptions are
external to your application code, which means that you can modify or adapt it without having to
modify your source code and recompile. For example, you can create XML layouts for different screen
orientations, different device screen sizes, and different languages. Additionally, declaring the
layout in XML makes it easier to visualize the structure of your UI, so it's easier to debug
problems.
When you compile your application, each XML layout file is compiled into a View resource. You should load the layout resource from your application code, in your Activity.onCreate() callback implementation. Do so by calling setContentView(), passing it the reference to your layout resource.
please do visit for more refference to http://developer.android.com/guide/topics/ui/declaring-layout.html

- 1,015
- 11
- 19
-
1ok. but I've already found solution to my problem on developer.android .but, this is valid answer. which is to be known by everyone. – sidVoter Apr 03 '17 at 20:31
-
1
which approach is good for my project
First of all, only you can tell what's good for your project, but the documentation https://developer.android.com/guide/topics/ui/declaring-layout.html gives some suggestions, with which I agree:
The advantage to declaring your UI in XML is that it enables you to better separate the presentation of your application from the code that controls its behavior. Your UI descriptions are external to your application code, which means that you can modify or adapt it without having to modify your source code and recompile. For example, you can create XML layouts for different screen orientations, different device screen sizes, and different languages. Additionally, declaring the layout in XML makes it easier to visualize the structure of your UI, so it's easier to debug problems.
Defining interfaces in XML is a better approach in most cases.
as user-experience point of view
The user experience will be the same regardless of defining UI in Java or XML, after all the interface will be the same.

- 3,782
- 2
- 19
- 26