기술적용

FlexboxLayout 적용

131 developer 2022. 1. 30. 19:30

 

 

FlexBoxLayout

  • 웹에서 사용되던 CSS Flexible Box Layout Module을 안드로이드에서 사용하기 위해 개발된 라이브러리다
  • 정해진 영역을 초과할 시 영역에 따라 줄바꿈을 해주는 기능이 있다

 

github

https://github.com/google/flexbox-layout

github에 정리가 아주 잘 되어있다.

 

적용

build.gradle(app)

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

 

XML

<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"
    app:flexWrap="wrap"
    app:alignItems="stretch"
    app:alignContent="stretch" >

    <TextView
        android:id="@+id/textview1"
        android:layout_width="120dp"
        android:layout_height="80dp"
        app:layout_flexBasisPercent="50%"
        />

    <TextView
        android:id="@+id/textview2"
        android:layout_width="80dp"
        android:layout_height="80dp"
        app:layout_alignSelf="center"
        />

    <TextView
        android:id="@+id/textview3"
        android:layout_width="160dp"
        android:layout_height="80dp"
        app:layout_alignSelf="flex_end"
        />
</com.google.android.flexbox.FlexboxLayout>