A simple aspect ratio layout for Android.
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
.
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>