Monday 29 November 2021

Create autofit view android

    We are going to create a view like this,




We can create view using FlexBoxLayout, 


Add the following dependency to your build.gradle file:

dependencies {
    implementation 'com.google.android:flexbox:1.1.0'
}



Adding the
FlexBoxLayout to the layout,


                        
<com.google.android.flexbox.FlexboxLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:layout_marginTop="30dp"
                app:flexDirection="row"
                app:flexWrap="wrap"
                app:justifyContent="flex_start">

                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:text="Sample Text 1" />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:text="Sample Text 2"  />
                <TextView
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_margin="2dp"
                    android:text="Sample Text 3" />
            </com.google.android.flexbox.FlexboxLayout>

No comments:

Post a Comment