3

Currently, i develop a android application. In my activity, i would like to place my elements according to their size. i explain : i have 3 LinearLayout in a GridLayout like this :

enter image description here

GridLayout (2,2, horizontal) allow to put the LinearLayouts like this :

enter image description here

I would like to do the same, but no with GridLayout(2,2,horizontal), but just according to the size of the element.

For example, if the screen is large, it's possible to have the 3 LinearLayout on the same line and inversely if the screen is small, juste 1 LinearLayout by line.

I hope I have been clear, Thanks in advance.

Gopal Singh Sirvi
  • 4,539
  • 5
  • 33
  • 55
Proutatis
  • 75
  • 7
  • I tried something like this before.. but I am using tons of LinearLayout and I am just playing with their layout_weight.. – Sheychan Jul 21 '15 at 09:16
  • You can use different layout xml files according to the desired size (http://developer.android.com/guide/practices/screens_support.html). If the LinearLayouts size can be different you have to change the layouts placement dynamically. –  Jul 21 '15 at 09:17
  • possible duplicate of [How can I do something like a FlowLayout in Android?](http://stackoverflow.com/questions/4474237/how-can-i-do-something-like-a-flowlayout-in-android) – Orabîg Jul 21 '15 at 09:20
  • Thanks for your answers, i'll try it. – Proutatis Jul 21 '15 at 09:29

3 Answers3

2

This layout would be a "FlowLayout" which doesn't exist in standard.

But there are some open-source implementations of it around :

You should take a look at

https://github.com/ApmeM/android-flowlayout

or

https://github.com/blazsolar/FlowLayout

Orabîg
  • 11,718
  • 6
  • 38
  • 58
  • Thanks, I have used it. Sorry for the duplicate, i didn't know FlowLayout before. – Proutatis Jul 21 '15 at 11:15
  • 2
    No problem ! There's no way to find for something - even on the internet - when you don't know its name, or even if it does exist... – Orabîg Jul 21 '15 at 11:29
0

Yes, of course you can do.

You need to create different layout directory for different density devices.

For example layout-ldpi, layout-hdpi, etc. and define the required kind of layout inside these.

res/layout/my_layout.xml             // layout for normal screen size ("default")
res/layout-small/my_layout.xml       // layout for small screen size
res/layout-large/my_layout.xml       // layout for large screen size
res/layout-xlarge/my_layout.xml      // layout for extra large screen size
res/layout-xlarge-land/my_layout.xml // layout for extra large in landscape orientation

And inside the different my_layout.xml file define either one, two or three linearlayouts you need.

Nabin
  • 11,216
  • 8
  • 63
  • 98