Skip to content

Instantly share code, notes, and snippets.

View AsheeshSharma's full-sized avatar

Asheesh Sharma AsheeshSharma

  • Zomato
  • New Delhi
View GitHub Profile
@AsheeshSharma
AsheeshSharma / dynamic_aspect_ratio.kt
Last active December 27, 2022 08:24
Dynamic aspect ratio handling with glide
fun setUpOneDimenNoAspectRatioImage(imageUrl: String?, imageView: AppCompatImageView, @DimenRes defaultHeight: Int, @DimenRes marginToBeAdjusted: Int, availableWidth: Int? = null) {
if (imageUrl?.isNotEmpty() == true) {
imageView.visibility = View.VISIBLE
GlideApp.with(imageView.context)
.load(imageUrl)
.centerCrop()
.into(object : CustomTarget<Drawable>() {
override fun onLoadFailed(errorDrawable: Drawable?) {
}
@AsheeshSharma
AsheeshSharma / custom_aspect_ratio_v2.xml
Last active April 1, 2022 09:11
Custom aspect ratio with fixed height
<AppCompatImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="@dimen/size_12"
android:adjustViewBounds="true"
android:scaleType="fitXY"/>
@AsheeshSharma
AsheeshSharma / custom_aspect_ratio.xml
Last active April 1, 2022 09:11
Custom aspect ratio with fixed max height
<AppCompatImageView
android:id="@+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:adjustViewBounds="true"
android:maxHeight="@dimen/size_12"
android:scaleType="fitXY"/>