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

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).

Related

How to decide which layout to use?

I have used both Linear and Relative layout . But still don't know excatly when to use which .
How to decide which one to use ? Explain with some example .
It's a personal preference for most of the cases.
You have to decide according to your necessity. You should however try to stick to RelativeLayout, if you are using multiple nested LinearLayouts since those can drop your performance noticeably.
See this tutorial. You'll have a good idea about different layouts. Hope this helps.. :)
This all depend on personal preferences and Experience matters a lot .
Personally i use combination of Linear layout in most of cases but sometimes FlowLayout and Relative Layout etc are used.
Linear Layout (vertical / Horizontal ) are used to create basic layout. Following properties help create view better and esthetic .
android:Layout_weight
Relative Layout is used to create overlay effect and also used to relate position of different Views according to position . Following properties help create view better and esthetic .
android:layout_margin
android:paddingLeft
android:paddingRight
android:paddingTop
android:paddingBottom
Frame Layout used to create Overlay layout like on option pressed etc.
also Frame Layout Can used to create overlay ads .
Grid Layout is used to create grid , you may have see gallery pics which are basically implemented in grid layout.
Example of Grid is Gallery Photos

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.

Android: How to organaze layouts

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.

Instructions layout for Android

I was looking into laying out some instructions on top of one of my applications like SoundHound does in one of their latest updates: http://i.imgur.com/D36nL.png
How is something like this achieved? Is this some sort of layout over another layout? Or a "dialog box" in a way?
You can create a frame layout with two children. The first would be the standard layout for the activity. The second would contain image views that display the help bubbles in the appropriate locations.
For more information see this: http://developer.android.com/guide/topics/ui/layout-objects.html#framelayout
Here is nice simple example: http://www.learn-android.com/2010/01/05/android-layout-tutorial/3/
You could just use a RelativeLayout with some elements having negative margins. They will overlap over other elements.

Categories

Resources