Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • FlexBox layout in android

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 340
    Comment on it

     In the below example I have describes "how to use FlexBox layout". FlexboxLayout extends the ViewGroup like relative layout and linear layout. You can add different attributes to the flexlayout like flexDirection, flexWrap, justifyContent, alignItems and alignContent. You can see below example code it clearly describes How to use FlexBox layout in android.

     

    Step(1)-I have added first Flexbox layout dependency to Grandle file -
    Introduction of library:- There is a Flexbox library which provides us the facility to create or to add a Flexbox layout in your application.


     

    compile 'com.google.android:flexbox:0.1.3'


    Step(2)-activity_main.xml layout-
     

    <?xml version="1.0" encoding="utf-8"?>
    <com.google.android.flexbox.FlexboxLayout xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical"
        app:alignItems="center"
        app:alignContent="center"
        app:flexDirection="row"
        app:flexWrap="wrap">
    
        <ImageView
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/one"
            app:layout_alignSelf="center" />
    
        <ImageView
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/img1"
            app:layout_alignSelf="center" />
    
        <ImageView
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="@drawable/img_3"
            app:layout_alignSelf="center" />
    
        <TextView
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:background="#805ac7b3"
            app:layout_flexBasisPercent="50%"/>
    
        <TextView
            android:layout_width="120dp"
            android:layout_height="120dp"
            android:layout_margin="5dp"
            android:background="#80d9e686"
            app:layout_alignSelf="flex_end"
            app:layout_flexBasisPercent="50%"
            android:fadeScrollbars="true"/>
    
    </com.google.android.flexbox.FlexboxLayout>
    
    

     

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: