data1 hello hi
data2 hello2 hi
data3 hi Hello
I want to konw what should be use,TableLayout?linearLayout or RelativeLayout?Which view realize the layout will more better?I also want to use XML code realize this layout,ask you for help,thank you!
Do you need anything to move around ? Interact with any of the objects?
If you just want something that simple, you can use the TableLayout. If you only need to support ICS (Android 4.0) and later, you can also checkout GridLayout.
LinearLayout is probably not your best choice in terms of performance (will do a lot of calculations for not much). If you have a lot of elements in your table, RelativeLayout is not best either.
You can also check this answer about TableLayout from a Google employee.
IT all depends entrely upon the GUI you want to design, how you want to place your GUI obejcts. The Android official site has a very informative and helpful tutorial on this topic:
http://developer.android.com/guide/topics/ui/declaring-layout.html
http://developer.android.com/guide/topics/ui/declaring-layout.html#CommonLayouts
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
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.
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>
I can't understand how this works in Android. I traversed samples and have no idea. For instance I need 2x2 grid view of TextView widgets. How to write needed code?
You can change the android developer example, on how to create a GridView, to meet your requirements.
Here's the full example.
Also if your beginning Android this would be a good book for you.
I'm using Relative layout for designing UI. Please give me guidelines to follow.
Hey, You can use Layouts according to the requirement that will depends on your application.
If you want to display the UI in table format then use TableLayout
If you want to display that line by line than use LinearLayout
like that you have to select the layout
Note: You can use multiple Layouts in the single Xml file that is in LinearLayout you can use tablelayout if required
You will find lots of tutorials here: https://developer.android.com/guide/practices/ui_guidelines/index.html.
Relative Layout
Hmm, I'd suggest looking at JQTouch ( http://sencha.com) which is aimed at web-kit browsers, including iPhone and Android. It has APIs to help you with layout and various transitions. Seems to work well in Dolphin although I have not tried it on the iPhone.