Android : Difference between Component and Widget? - android

what is the difference between Component and Widget? in the Android UI Design Level. Difference between Java Class Creative UI and using .xml layout file design?

"widget" for subclasses of View that have a visual representation to the user by default -- things like TextView, Button, ListView, etc.
I tend to use the term "view" for something that could be any subclass of View, including pure containers like LinearLayout.
But, again, there is no particular harm in referring to them by either term.

Related

Dynamic UI Controls in Android

I am in a situation like i have to generate UI Controls like Button,Switcher,Progress Bar, Label text etc based on my list Items .
I am looking for a way to generate the controls in a View and add Views with generated controls in a Layout .
Can anyone give me a proper way to do that?
Why not to use Fragments?
Google docs about this here
and little tutorial here
You may want to take a look at the Metawidget source code. The Android version of Metawidget makes extensive use of generating Views and Layouts at runtime (e.g. see org.metawidget.android.widget.widgetbuilder.AndroidWidgetBuilder). You may even find Metawidget itself will suit your needs (it's designed to be embedded into projects for use-cases such as this).

What makes Android GUI framework

Java is used to bring up gui components like View and Widgets. Official site say they dont include AWT/Swing as a part of their java bundle, then what implementation (native-wrapper if any?) they have in place? Also is it possible to create user interface from scratch for android apps without extending any View class?
It's a custom UI toolkit unrelated to AWT or Swing.
You can create custom subclasses of the View class to draw whatever custom components you would like, but most of the time you can set attributes on the existing components to change the way they're drawn (like setting the drawables for a button).

How do I get about adding something to my Android Layout?

I am a complete newb to Android and have seen tutorials that show widgets being added via XML and also via Java. I want to know what industry experts prefer and why. The author/narrator seems to prefer XML saying it gives more control but I wanted to get feedback from veterans.
With XML Tutorial
Without XML Tutorial
Thank You and again I apologize for a complete newb question.
XML layouts are very easy compared to java code. The coding also very less than java.
You can prefer any of these two, but all authors prefer XML because its easy.
Please read information available at this link, you will get an idea.
XML Layouts
Declare UI elements in XML (most
common and preferred)
Android provides a straightforward XML vocabulary
that corresponds to the View classes and subclasses,
such as those for UI controls called widgets
(TextView, Button, etc.) and layouts.
Instantiate layout elements at
runtime (programmatically in Java code)
Your application can create View and ViewGroup
objects (and manipulate their properties)
programmatically (in Java code).
Advantages of : Declaring UI in XML
• Separation of the presentation from the code
that controls its behavior
You can modify UI 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
• Easier to visualize the structure of your UI
(without writing any code)
Easier to design/debug UI
Visualizer tool (like the one in Eclipse IDE)
Advantages of : Instantiate layout elements at runtime
• While showing dynamic data
When your application need to show dynamically some information for example loading title from web then you need as many text-view per title and you are not sure at design time about this at that time this can be preffered
You can make your application design both ways and both will help you the same,It will depened on your requirement whether you require to create it at runtime or not,Anyways I think while you can make separate XML file why need to do it in your Activity java file and get more complexity in code unnecessarily.
XML layout method is very easy, fast and easy to visualize. You can do a paper-pencil work first and simply do it in XML.
XML layouts are easy to manage - you can change the caption, position, look & feel, size, colors etc. in the XML layout, without altering a single line of the Java Code. The App will generate the Java Code for the layout from your XML file.
XML layout does not compell that you should write the whole XML codes. Instead, you can use a GUI editor and you arrange the controls on screen, and it will generate the XML for you. There are lots of GUI design tools. Eg.: http://www.droiddraw.org
Now, you can go for Java Code UI layout only if you cannot determine the layout at the time of writing the App. Say, you are designing an Android App for Web Designers - An app to create HTML Forms and create the HTML code (a simple HTML editor tool), then you are unable to know which type of layout the user is going to do. At this point, the better option is choosing Dynamic Layout (or Java Code layout)
Almost every Android programmer chooses to do layout in XML. That's the beast and easiest way to do it.

Tips on making custom, reuesable components in Android

I want to create a component that will appear as a navigation menu for an Android application. Basically, the custom component is a rectangular "Div" (to use HTML terms) that contains six buttons. Each button provides a link to another part of the application. I want to use this on every "page", so I want to make it easy to maintain.
What is the recommended class to extend for creating custom components like this? (I've seen the "Widget" class, but not sure If this should only be used for widget that appear outside the app (like Google search))
And
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
The class to extend is View, the Widget class is for widgets in the homescreen. This is a nice doc to read: Building Custom Components, I suggest to look at the Compound Controls section, that seems suitable for your problem.
Is the process as simple as creating the custom "Widget" class with it's own XML layout and then adding it to each Activity class?
Yes, once you have written your own view, you just have to add it to your layouts in the XML (just like you do with the android views), something like this:
<com.your.package.YourNiceView
android:layout_width="fill_parent"
android:layout_height="fill_parent"/>

How to structure Android views in xml logically

I want to put view elements that belong together in a container (e.g. a label and input field). This is useful for example to show/hide these elements all at once. The container, however, is only to group them logically, i.e. I don't want to change the layout with the additional containers.
If I look at HTML, there you can use a div element to structure elements together. When applying a style or removing this element, then its children are affected by that as well. I am looking for something like this in Android.
Android has an abstract ViewGroup, yet I cannot use this directly. Android Studio tells me "Element ViewGroup is not allowed here". I don't want to use a LinearLayout because I don't want to change the layout. Is there a ViewGroup that does nothing, besides adding structure to the XML?
Alternative idea:
Maybe I could use the android: tag attribute for this. Such that I construct a method to "hide all elements that contain tag X". Or more generally "perform action Y of elements with tag X". With this approach I would try to emulate what classes do in CSS/HTML: Give elements attributes, query elements using these attributes, apply styles/actions on these elements.
Does anyone have experience with such an approach in Android?
Bonus question:
When looking at Android I get the feeling that very flexible and useful concepts, which are mature and well known from web development, have been lost. For example, in Android XML you can set one style on a view. However, using HTML/CSS you typically set a multitude of classes to elements and can create a style for each one of them. For instance elements with class "important" should be bold, with class "title" should have a larger font, thus an element with both "important_text" and "title" would be bold as well as large. How would you do this in Android?
Take a look how <include> and <merge> layout tags are working. Probably that's could be close to that you are searching.

Categories

Resources