A library to achieve a view group with aspect ratio attribute
Gradle
dependencies {
implementation 'com.github.arefbhrn:aspectratiolayout:1.0.4'
}
Define 'app' namespace on root view in your layout
xmlns:app="http://schemas.android.com/apk/res-auto"
Include this library in your layout
<com.arefbhrn.aspectratiolayout.AspectRatioLayout
android:id="@+id/container_ratio_layout"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:aspectRatio="0.5"
app:isRatioHeightToWidth="true">
// any other layouts
</com.arefbhrn.aspectratiolayout.AspectRatioLayout>
XML Attribute | Programmatic Setter | Description |
---|---|---|
app:aspectRatio | setAspectRatio(float ratio) | aspect ratio (height / width). |
app:isRatioHeightToWidth | setRatioHeightToWidth(boolean ratioHeightToWidth) | if true: aspect ratio = (height / width), otherwise: aspect ratio = (width / height) |
If you have a better idea or way on this project, please let me know, thanks :)
This project is licensed under the Apache 2.0 License - see the LICENSE.md file for details