is there a custom UI element on android that will behave like iOS collection view?
[like a grid view, that is scrollable]
or do I have to make a custom table layout custom cells that behave like columns?
here a shot of a UICollectionView for iOS
is there an example for this?
thanks!
Since the previous answer does not reflect performance issues, such as it does not use recycling (which is important for long lists), here is what you are probably looking for:
GridView if your building blocks are all equal in size
http://developer.android.com/guide/topics/ui/layout/gridview.html
or ListView (and a lot of custom logic) if your building blocks have different sizes/widths
http://developer.android.com/guide/topics/ui/layout/listview.html
I don't know the collection view in iOS, but I guess TableLayout is what you are looking for.
https://developer.android.com/reference/android/widget/TableLayout.html
In API14+ there is GridLayout as well.
https://developer.android.com/reference/android/widget/GridLayout.html
Gridview is best replacement of Collection View of IOS. following URL will solve your problem.
http://developer.android.com/guide/topics/ui/layout/gridview.html
This is old, but the Google team have created a widget used in the IO 2014 app that's perfect. It allows for variable column rows and even headers out of the box.
https://github.com/google/iosched/blob/master/android/src/main/java/com/google/samples/apps/iosched/ui/widget/CollectionView.java
You'd have to dig through the source for how it's used, but it's really easy and great to use.
Nowadays RecyclerView is what you're looking for. GridView and others are considered legacy API now. RecyclerView is able to handle these type of layouts more efficiently.
Related
I have an existing website for which I have to make an Android application. I have something a table with multiple columns(20) on the dashboard of website.
What will be an appropriate option to implement this? The screenshot of the table : https://drive.google.com/file/d/0B6SgMBRKkQ60WHB3bFc4Z2Y2cWM/view?usp=sharing
I had a look at TableLayout, but that might make the app look a little clumsy. Also, I learnt about horizontal ListView. Will that be a better option?
I think you should go with GridLayout.
http://androidexample.com/Grid_Layout_-_Android_Example/index.php?view=article_discription&aid=75&aaid=99
above is reference for GridLayout.
and this is official android blog spot link for GridLayout.
http://android-developers.blogspot.in/2011/11/new-layout-widgets-space-and-gridlayout.html
You can use a custom list view Or a GridView
Good examples to begin are below:
http://androidexample.com/How_To_Create_A_Custom_Listview_-_Android_Example/index.php?view=article_discription&aid=67&aaid=92
http://androidexample.com/Custom_Grid_Layout_-_Android_Example/index.php?view=article_discription&aid=76&aaid=100
I would like to build a specific layout for an android application. Actually, I would like to obtain something with the same behavior as inline-block div in html/css... I don't really know if I should use a LinearLayout or a GridLayout or something else...
It's like a horizontal LinearLayout but when the line is full, I would like my objects to go on the next line... I'm going to add the items programmatically to the container...
Here's an example of what I would like to do:
Do you have any idea?
Thanks by advance,
Valentin
Instead of using a layout, it might be easier to use a GridView because they will only use memory for items on screen and can be added using an adapter.
Read more here: http://developer.android.com/guide/topics/ui/layout/gridview.html
Android provides a GridLayout component (along with the helper view Space which can be used to build a flexible layout with multiple rows and columns, as explained in The Android Developers Blog. It is available as of Ice Cream Sandwich (v14) or as part of the v7 support library, and hence available to all 2.1+ devices.
I have to make a custom list view with custom header, ( different text in each headers) and different number of items below each header. I have been going through various section indexing examples but I think they are not relevant much to my answer.
Anybody please suggest me a good means to move around such type of list view in android.
This might be a duplicate of Android Listview with sections
There are lots of different ones out there. One example is: http://w2davids.wordpress.com/android-sectioned-headers-in-listviews which uses: http://jsharkey.org/blog/2008/08/18/separating-lists-with-headers-in-android-09
That one allows you to pass in different array adapters for each section so that you can have different layouts for each section's items.
If you were more clear about what the ones you have seen fail to do that you need it would be easier to offer you something you haven't seen.
There has been lot of thread exists on the Stackoverflow, check:
Android Listview with sections
Android ListView section header
How to draw a section header in Android listview just like the Contacts app did ?
But I am not sure these threads has helpful info, but if you want to read, understand and implement ListView with sections then here is one of the great and detailed article given by Cyril: ListView Tips & Tricks #2: Sectioning Your ListView
For a more complex design with sections in list, you should try this very standard library : https://github.com/emilsjolander/StickyListHeaders.
Other alternatives mentionned are great.
I should mention that the only drawback of this library is a poor mavenization and its absence on central.
Try this tutorial..its very nice and simple
http://www.androidhive.info/2013/07/android-expandable-list-view-tutorial/
There's a very good library for this. I've used in a project or 2 myself. Check it out:
https://code.google.com/p/android-amazing-listview/
Why can't you use expandable list view?
this link might help you: Android Exandable listview tutorial
I'm building an App for Android that already exists for iOS. On iOS, we really like to use the listview grouped style to show details and forms. It is really useful to show details of objects that we don't know how much properties they have before loading it.
I know that Android doesn't have a similar tableview style. And I don't want to use a custom library to recreate it, because I don't want to force an iOS like interface to my Android's users.
But how would you create a consistent Android interface that show similar information? Do you have example for me?
First of all, your instinct to not force iOS style UI onto Android users is correct and I respect you for it.
Android's ListView is roughly the equivalent of iOS's UITableView. There are important differences. For instance, you should never use a ListView inside another scrollable container. If a ListView is in a particular layout, it should (usually) be the only scrollable component. If you want multiple ListViews in a layout, you probably don't want ListViews at all. You should instead use (vertical) LinearLayouts and add the items in order.
Cyril Mottier writes excellent posts on implementing custom behavior for Android's ListView.
If you want to display data in a list then you can use the ListView. Here is a great article about how to use it.
I don't think I have really ever nested more than about three levels worth of Layouts (RelativeLayout, LinearLayout, FrameLayout) in Android. I am not thinking about list items which also use a custom layout for ListView but just normal layouts for an activity.
To the point though, I was chatting with another developer about nesting layouts for a certain layout we were discussing and he seemed to think that even a few nested layouts really slowed down performance. I figured there is some truth but it cant be that much.
Does anyone have a more expert approach to this? Any input? Opinion?
Thanks.
UPDATE for those who found on Google:
The first answer below is a great resource. It looks like a lot and people seem to skip over answers like that but please check it out. Very valuable.
I guess there is no silver bullet for this but I will give you some tips:
1) Try using the tools provided with the android sdk.
I tend to analyze my layouts with hierarchyviewer and layoutopt trying to reduce the amount of View used and the height of the tree.
2) Read Romain Guy's posts about <include>, <merge> and <ViewStub>
These tags are not used often but they provide great speed "hacks".
http://www.curious-creature.org/2009/03/01/android-layout-tricks-3-optimize-part-1/
http://www.curious-creature.org/2009/03/16/android-layout-tricks-4-optimize-part-2/
3) Use dmtracedump and measure how long does it take to inflate a view.
You can check how long it takes to inflate a view. Get an inflater and measure how long it takes to inflate each of your options.
I havent done any proper testing to support this, still, I believe that android was design to use nesting Layouts in order to provide adequate UI's to the user, its practically the only way to support multiple screens so I wouldn't really worry about which is the most efficient, just that it looks the way it should.
Any other kind of bad programming practice would probably have a bigger effect in efficiency than layout nesting.
The difference will be much more important when you use such a layout for every item in a ListView for instance. Hopefully this simple example showed you that getting to know your layouts is the best way to learn how to optimize your UI.
Can't give you a full answer, but Romain Guy has specifically stated that nested RelativeLayouts have an exponential time for measurement.
See video here at 38:08 mark
actually all of them are based on the same class..
but it would be better to use according to me as follows:
<RelativeLayout>
<LinearLayout>
<at> here we just create nested more as we wont></at>
</LinearLayout>
</RelativeLayout>