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.
Related
I have used localization in my android application. Which supports two kind of layout in application.
I have used Fragment and Fragment Activity in my application.
If language is English then layout should be aligned to left as shown in image below.
And if language is Hebrew then layout should be aligned to right as shown in image below.
I am trying to load this layout by two different layout files and then I can detect which language and I can use appropriately.
Is there any other good methodology through I can use achieve this functionality without creating different XMLs for all layouts?
Can anybody please help me to resolve this issue?
This should help:
http://developer.android.com/about/versions/android-4.2.html#RTL
Android supports right-to-left layouts natively since android 4.2.
Creating two similar layouts those are having same #+id values is a clean approach but if you don't want to create two different layouts then you could simply set the layout_gravity attribute by code with some helper method and by getting the LayoutParams of the containers you are using in your xmls.
Edit :
From another answer , If it works for you with the support package i.e. v4 if you are targeting 2.2+ above then this would be an awesome approach to go with.
http://developer.android.com/about/versions/android-4.2.html#RTL
just came to know about this. Android is awesome!!
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 am working on an application that involves me having to place a toolbar at the bottom of each activity. The toolbar will have 4 buttons on it, each starting new activities.
I am just wondering, and I apologize for how general the question, is there a proper way to go about implementing this? my plan was to but a linear layout element in each xml layout file with horizontal orientation. Then four button elements inside of that...
It seems like a huge amount of work considering I will have a lot of activities..
What you want sounds a lot like Android's ActionBar. Check this link for a guide to its usage. If you use this, your app will look and feel more consistent with the operating system, as so many apps now use the ActionBar (which is a lot of them), and you gain a lot of power for what you want to show there, and how you want to do it.
ActionBar was only introduced in Android version 3 (Honeycomb), but there's a compatibility library, ActionBarSherlock which allows you to use it in older versions of Android as well.
Hope it works for you!
You can use a same xml for various views. So I suggest creating a generic xml, then using Inflaters and other resources as strings, xmls etc. to prepare the generic xml whenever any Activity is loaded. So you can reuse it the xml.
I am very new to Android development and am having some trouble. I am creating an XML file using Eclipse, both the Graphical Layout feature is what I'm having trouble with.
Also, I am working in Android 2.3 for compatibility reasons.
I am wondering if there is a layout which enables me to place buttons or text fields or any attribute where I want to put them. This may sound stupid, but it seems that every layout has some sort of order in which it lets you add attributes, and whenever I try to drag them elsewhere on the layout things just get very very messy.
If what you want is an AbsoluteLayout, this has been deprecated since Android 2 (IIRC). You can try using the RelativeLayout, which let you position freely your widgets. Else, if you only use LinearLayout, then yes the widget will be positioned in a strict way.
use Relative Layout. I recommend that you read up on Android layouts so you understand why, what and hows of Android way. There are some good tutorials that I found helpful. TutsPlus: Android Layouts
There is also a very good video from Marakana.
Marakana: Android Bootcamp
If you are just starting out with Android check other tutorials/videos on Marakana. They are a very good resource for beginners.
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.