Android: How to organaze layouts - android

I need to organize complicated Activity with many Views inside.
Also layout should depending on screen orientation.
Inner elements - it actually some templates.
Help me please to find out what is the best way to organize this?
Should I create layouts dynamically or I can create some xml templates and use them?
And if I want to realize Template3 as clickable element is it enough to define onListItemClick for ListView (ListItem has an xml declaration, so the ids will be the same for all elements).
And all the template elements should have the same width and height. It's OK with the ListView, But what to do with Template1? I want each items has the same height, and match parent view.
How to organize onConfigurationChanged() ? Where and how I can realize adding or removing 3 additional Template1 elements? Dynamically? Or create 2 xml?
What is the best for performance?
Maybe someone can give me a link to "example of complicated layout" or something like this? :)

Try searching on concept of fragmentation,it will solve the problem.

Related

What techniques do you think duolingo used to make its lesson list in the app?(pic included)

I'm trying to make the duolingo lesson list for fun because im a big fan of the app, im a beginner programmer.
basically id like your opinion on how you think they did it.
here is what it looks like
https://s-media-cache-ak0.pinimg.com/236x/a3/a8/65/a3a865c47153078e7004b74652af7757.jpg
I think it might be a scroll view and linear layout, then perhaps a class for each icon/progress/name combo that will change based on progress
I think a table layout might be an easier solution.
Check it out here: https://developer.android.com/guide/topics/ui/layout/grid.html
I figured out how to do it, you need to use a scrollView followed by a linearlayout.
Then you can programatically add in relative layouts as rows and in those relative layouts make another square relative layout and in that relative layout you stack up the stuff like image/text/progress

Need suggestions for dynamically creating views in android

I am going to start one app where my activity page will contain "n" grouped views. Grouped view means "collections of views (i.e. One group can have TextView+Button+ImageView)". So the page will have "n" number of such grouped views.
I need suggestions like what would be the best practice to implement this. I could think of below ones:
1) Should a ScrollView be used (Then I will have to create groups in runtime and place one under another)?
2) Or a ListView be used (Then how can I accommodate the height of each row as grouped views height may differ from each other?)
Or is there any other way I can go along with?
Appreciate the suggestions and any sample examples if have. Advance Thanks.
Both options would work, it really depends on your use case.
Place a vertical LinearLayout inside of a ScrollView and add your grouped-views to the LinearLayout. I would recommend this if you have a relatively small number of such views (not necessarily a fixed number, but small enough that you wouldn't have to scroll many "pages" to see them all). Make sure the ScrollView has android:layout_height="match_parent" and the LinearLayout has android:layout_height="wrap_content".
If the number of grouped-views is not small, you could use a ListView and make an Adapter for it. This lets you take advantage of ListView's automatic view recycling when items get scrolled off screen.
For either case, make an XML file for just the grouped-views. In code, you would get a LayoutInflater object (usually by calling Activity.getLayoutInflater()) and call inflate(R.layout.your_grouped_views, null). If using the LinearLayout, you would add it in code with one of the LinearLayout.addView(..) methods; if using the ListView, your adapter would return the whole thing from getView(...).
create one xml layout containing the constant elements of your group view.
in you main xml layout which will be the contentView of your application, put a ScrollView and a single LinearLayout.
then in the program inflate as many views of your group view as you want.
For your answer i want to give you referance of this website, on this website you can learn create dynamic view in android...

How to place UI elements to the position we want in Android?

I have some buttons, textboxes etc. in my android application, but when i drag them with my mouse in the xml file, their place doesn't change, or changes but they are not placed where i exactly wanted. How can i adjust their positions in the screen?
Thanks
Unfortunatly there is no such thing as absolute positionning in android ( RIP AbsoluteLayout deprecated since years.)
instead you have to position views according to their parents and according to other views in the same parent.
first you have to define wich parent you need ( if you want some viens in a single line go for a LinearLayout. a more custom layout: use a RelativeLayout ...)
then you can drag and drop views inside, but they will always snap a position relative to their parent and/or relative to the other views.
you can of course play with margins.
A list of layout type with some advanced techniques can be found on this page
Hope that helps.
You RelativeLayout as a group layout for your layout so positioning can somewhat easy using mouse.
Best is to arrange them from the xml code. Just Learn about using the Relative layout, LinearLayout and TableLayout
Learn how the XML works. For a LinearLayout, the items come in the order listed. For a RelativeLayout, the items are related by the values of their layout_XXX properties. Then you don't have to worry about the WYSIWYG tool not working.
FYI, the tool bundled with eclipse is extremely buggy. Don't count on whats on there being what's on your phone for anything non-trivial.
Like the others wrote it is easier to edit layout using xml editor. You can read more here http://developer.android.com/guide/topics/ui/declaring-layout.html.

Which layout should I use so my app looks like Google Plus?

I'd like to make a layout similar to the one used in the current version of Google Plus:
I don't know which layout I must use because :
- I can't use a GridView because it doesn't support spanning row.
- I can't use a GridLayout nor LinearLayout because the number of elements to show is dynamic
- I can't use a ScrollView because I want an AdapterView to re-use child elements
- I can use a ListView with two differents cells types but I can't use the built-in OnItemClickListener.
Do you have better ideas than me?
Thank you very much :)
this post suggested that it uses StaggeredGridView . I personally haven't tried it.
You can very well use RelativeLayout for this.
With a single Relative Layout you should be able to create exactly same layout.
Additionally, your content can be dynamically added to Relative Layout pretty easily (by setting proper LayoutParams to the content to be added).

How can I make a listview with more than a title?

I would like to have a special listview with a title, couple of sub-categories, and a picture. The picture below is a rough idea of how I would like to lay it out. I am very new to android so keep in mind that details really helps me. Thank you in advance.
You can create an xml layout that is used for each ListView item. If you haven't yet, read through Common Layout Objects for an introduction to the different layout types. There are also a "Hello layout" tutorial for each layout type, linked from that page.
In this case, you could use a horizontal LinearLayout with a vertical LinearLayout and an ImageView inside of it.
To bind your objects to the views within your ListView item, use a SimpleAdapter. You can find a number of tutorials on SimpleAdapters if you search around, for example.

Categories

Resources