/AspectRatioImageView

AspectRatioImageView

Primary LanguageKotlinApache License 2.0Apache-2.0

AspectRatioImageView

With this library, you can display photos with their original aspect ratio within any screen size.

Demo

Usage

Gradle

Step 1. Add it in your root build.gradle at the end of repositories:

allprojects {
  repositories {
	maven { url 'https://jitpack.io' }
  }
}

Step 2. Add the dependency

dependencies {
  implementation 'com.github.mehdiyari:AspectRatioImageView:{latest_version}'
}

Gradle-Kotlin-DSL

Step 1. Add it in your root build.gradle.kts at the end of repositories:

repositories {
  maven {
    this.url = URI("https://jitpack.io")
  }
}

Step 2. Add the dependency

implementation("com.github.mehdiyari:AspectRatioImageView:{latest_version}")

Maven

<repositories>
  <repository>
	 <id>jitpack.io</id>
	 <url>https://jitpack.io</url>
  </repository>
</repositories>
<dependency>
  <groupId>com.github.mehdiyari</groupId>
  <artifactId>AspectRatioImageView</artifactId>
  <version>{latest_version}</version>
</dependency>

Simple usage

In XML

<ir.mehdiyari.ariv.ui.AspectRatioImageView
  android:layout_width="wrap_content"
  android:layout_height="wrap_content" 
  android:src="@drawable/photo"/>

In Code

// kotlin
AspectRatioImageView(this@MainActivity).apply { 
  setImageDrawable(ContextCompat.getDrawable(this@MainActivity, R.drawable.photo))
}
// java
AspectRatioImageView aspectRatioImageView = new AspectRatioImageView(this@MainActivity);
aspectRatioImageView.setImageDrawable(ContextCompat.getDrawable(this@MainActivity, R.drawable.photo));

Attributes

Attribute name Type Description
ariv_minWidth dimension Min width of ImageView
ariv_maxWidth dimension Max width of ImageView
ariv_minHeight dimension Min height of ImageView
ariv_maxHeight dimension Max height of ImageView
ariv_adapterMode boolean If you are using ariv inside
recyclerView set adapterMode to true
ariv_src reference image source

note:
Because AspectRatioImageView used RoundImageView as base imageview you can use all of attributes RoundImageView too

License

Copyright 2020 Mehdi Yari

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

   http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.