Skip to content

TakWolf/Android-AspectRatioLayout

Repository files navigation

Android - AspectRatioLayout

Platform API License JitPack

A simple aspect ratio layout for Android.

Screenshot

Screenshot

Usage

repositories {
    maven { setUrl("https://jitpack.io") }
}

dependencies {
    implementation("com.github.TakWolf:Android-AspectRatioLayout:0.0.1")
}
<com.takwolf.android.aspectratiolayout.AspectRatioLayout
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:arl_widthRatio="4"
    app:arl_heightRatio="3">

    <YourView />
    
</com.takwolf.android.aspectratiolayout.AspectRatioLayout>

That's it!

PS: AspectRatioLayout is extends FrameLayout.

Another way

There is another way to make aspect ratio layout by ConstraintLayout like:

<androidx.constraintlayout.widget.ConstraintLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    <View 
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="?colorPrimary"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constrainedHeight="true"
        app:layout_constraintDimensionRatio="16:9" />

</androidx.constraintlayout.widget.ConstraintLayout>

License

Apache License 2.0

About

A simple aspect ratio layout for Android

Topics

Resources

License

Stars

Watchers

Forks