Search code examples
androidandroid-linearlayoutandroid-relativelayout

Android - make all RelativeLayouts like floating left and going automatically in new lines


I have this scenario :

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
.... >

    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        
        <ImageView as label ... />
        
        <TextView text content.... 
          android:layout_toRightOf=label />
        
    </RelativeLayout>
    
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        
        <ImageView as label ... />
        
        <TextView text content.... 
          android:layout_toRightOf=label />
        
    </RelativeLayout>   
    
    <RelativeLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content">
        
        <ImageView as label ... />
        
        <TextView text content.... 
          android:layout_toRightOf=label />
        
    </RelativeLayout>   

    .
    .
    .
    .
    
</LinearLayout>

And I wanted all those relativelayouts to position automatically each one next to the previous and going automatically at new line if mobile phone is vertical and going automatically in one line if mobile phone is horizontal... I tried with GridLayout but looks like is not so good because contents textviews have different lenght depends from informations I get... is there a way to solve that? Thanks! Cheers!


Solution

  • Android framework doesn't have such option built-in, you could write it by own, but Google did that for you. check out flexbox-layout library