0

Library: implementation 'com.google.android.material:material:1.0.0'

XML:

  <com.google.android.material.floatingactionbutton.FloatingActionButton
            android:id="@+id/fab"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginRight="@dimen/dimen_16_dp"
            android:visibility="visible"
            app:fabCustomSize="80dp"
            app:maxImageSize="80dp"
            android:scaleType="center"
            android:layout_alignParentEnd="true"
            android:layout_above="@id/layout_privacycardview"
            android:padding="0dp"
            android:src="@drawable/ic_football" />

Output: Desired result

Now, I want to set the image resource programmatically as well as dynamically using Glide.

   String url = "https://encrypted-tbn0.gstatic.com/images?q=tbn:ANd9GcSyKmXIim9sp4B4Mn1N_NJtRkzvkStZo_s5pA&usqp=CAU";
        Glide.with(HomeScreenActivity.this).load(url).into(fab); 

Output:

Issue

How to set the image resource dynamically using Glide, such that it can have its proper imageSize etc.

user14678216
  • 2,886
  • 2
  • 16
  • 37
Sharan
  • 1,055
  • 3
  • 21
  • 38

2 Answers2

0

You need to make icon circle as below -

 String url = "https://encrypted-tbn0.gstatic.com/images? 
 q=tbn:ANd9GcSyKmXIim9sp4B4Mn1N_NJtRkzvkStZo_s5pA&usqp=CAU";

    Glide.with(HomeScreenActivity.this) 
    .load(url)
    .apply(RequestOptions.circleCropTransform())
    .into(fab);
Priyanka
  • 1,791
  • 1
  • 7
  • 12
0

Just use

.override(width,height) and pass in desired width and height values and also add .apply(RequestOptions.circleCropTransform())

Example :-

Glide.with(HomeScreenActivity.this).load(url).override(80,80).apply(RequestOptions.circleCropTransform())into(fab);
Sociopath
  • 15
  • 4