I have an ImageButton that doesn't have any background.
I have a png to be used as an Image for the button. How can I do it with glide (my image is in the drawable folder)?
This is my code:
activity_main.xml:
<RelativeLayout
<ImageButton
android:id="#+id/ib_main_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
/>
</RelativeLayout>
MainActivity.java:
ImageButton ib_main_home;
Glide.with(MainActivity.this)
.load(R.drawable.home)
.placeholder(R.drawable.home)
.centerCrop()
.into(ib_main_home);
If the image is in drawable directory, you don't need Glide.set src property in xml. remove glide code from activity
<ImageButton
android:id="#+id/ib_main_home"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#android:color/transparent"
android:scaleType="fitCenter"
android:src="#drawable/home"/>
You may also set image through activity like below
ib_main_home.setImageDrawable(R.drawable.home)
You should use custom targets, in particular a ViewTarget. Take a look at the wiki.
in your case:
Glide.with(this)
.fromResource(R.drawable.home)
.into(ib_main_home);
If the image is in drawable directory, you don't need Glide. Just do:
imageButton.setImageResource(R.drawable.home)
Related
I'm using Glide library to get user's profile image from url and display it in ImageView view.
I want to set camera icon on the right side of that profile image exactly like below.
Here is my imave view:
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_marginTop="700dp" />
Glide:
ImageView imageView = findViewById(R.id.imageView);
Glide.with(imageView)
.load(URL)
.circleCrop()
.placeholder(setCircularImage(R.drawable.prof))
.error(setCircularImage(R.drawable.t))
.fallback(setCircularImage(R.drawable.camera_red))
.into(imageView);
How could I do that, Whic library should I use to make camera icon on the right side of a profile image ?
I don't want the icon overlap the profile image. I want the profile image to be cropped to give place to camera icon(Like on facebook app profile image). Thanks.
Thanks.
There is nothing to do with Glide. You can use ConstraintLayout, FrameLayout or RelativeLayout to overlap ImageViews.
you can use Relative layout to achieve this like below
<RelativeLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<ImageView
android:id="#+id/imageView"
android:layout_width="50dp"
android:layout_height="50dp"
android:src="#drawable/ic_launcher_background"
android:layout_marginTop="700dp" />
<ImageView
android:layout_width="wrap_content"
android:layout_alignBottom="#id/imageView"
android:layout_alignEnd="#id/imageView"
android:layout_height="wrap_content"
android:bott="true"
android:src="#drawable/abc_vector_test"
/>
</RelativeLayout>
and then adjust it accordingly.
Happy coding :)
first you should use circleImageView in your layout and then set two of them like this:
<CircleImageView
android:id="#+id/circleImg1"
android:layout_width="50dp"
android:layout_height="50dp"/>
<CircleImageView
android:id="#+id/circleImg2"
android:layout_width="15dp"
android:layout_alignBottom="#id/circleImg1"
android:layout_alignEnd="#id/circleImg1"
android:layout_height="15dp"/>
I have to take a picture in my App. After take it , I have to show it in a ImageView, so I decided to use Glide as library to handle it.
I have set the code like this:
Glide.with(this)
.load(mLastPhoto)
.fitCenter()
.centerCrop()
.into(iv_circ_image);
and the xml file looks like:
<ImageView
android:id="#+id/circ_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bTakePicture"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="12dp"
android:src="#drawable/ab_background_textured_" />
But when the phot has been taken, the image is shown like this:
How I have to set the Glide code or the XML to show all the image?
Add the android:adjustViewBounds="true" attribute to your ImageView. Set this to true if you want the ImageView to adjust its bounds to preserve the aspect ratio of its drawable (from API-Documentation http://developer.android.com/reference/android/widget/ImageView.html).
<ImageView
android:adjustViewBounds="true"
android:id="#+id/circ_image"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/bTakePicture"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp"
android:layout_marginTop="12dp"
android:src="#drawable/ab_background_textured_" />
In the xml you have android:layout_height="wrap_content" and android:layout_marginTop="12dp"
Then in the java you have .fitCenter().centerCrop().
So basically you have a 12dp image view that Glide is filling. I suggest you set the height of the image view (ie 200dp) or have the buttons stick to the bottom of the screen and have the imageview fill the available space between them.
I have to show circular profile picture with border around it. I have a background image for border. I am setting image "src" with padding of 3 dp.
My Image view in XML looks like:
<ImageView
android:id="#+id/pic_iv"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/blank_avatar"
android:padding="3dp"
android:scaleType="fitXY"
/>
I am setting image to this image view using "setImageBitmap(Bitmap bitmap)" programatically.
I googled and tried setting property
android:cropToPadding="true"
but this is also of no use. Padding is being ignored. so no border is shown around image.
Any help will be highly appreciated.
this is what i have done to make the borders
1st - in the layout file i did the following :
<ImageView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:src="#drawable/ic_launcher"
android:background="#123456"
android:padding="10dp"
android:id="#+id/imageView"
android:scaleType="fitXY"/>
2nd - in my activity i used the same method you are using to change the image "setImageBitmap(bitmap)" like the following :
ImageView imageView = (ImageView)findViewById(R.id.imageView);
Bitmap bitmap = BitmapFactory.decodeResource(getResources(), R.drawable.aaaa);
imageView.setImageBitmap(bitmap);
and i got a image with the padding around it with 10dp like the image attached.
Hope that helps .
Change properties of ImageView android:scaleType="fitXY" to android:scaleType="center" or android:scaleType="fitCenter" and try again .
Hope this will work .
I need to put my own image on some imageView. So that's why I created folder named "drawable" in res folder , and copy my Image in this folder , but now I don't know how to set this image to my imageView in XML code. Can anybody help? and sorry for English :)
In your layout XML file:
<ImageView android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/your_image_name"/>
Replace your_image_name with the name of the image file without the extension (e.g. if your drawable file is called img1.png, the src attribute should have a value of #drawable/img1).
Set it using android:src=""
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/image_name" />
Try this.
<ImageView
android:id="#+id/YourImageViewID"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/Your_Image_Name"
/>
This may help you.
//set background as your image by calling the android:background attributes in your xml
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="#drawable/myimage"
/>
Note: you no need to create any drawable folder by default android project will contain
drawable-mdpi
drawable-hdpi
drawable-ldpi
you can put your image in that.
<ImageView
android:layout_width="150dp"
android:layout_gravity="bottom"
android:layout_height="150dp"
android:id="#+id/image1"
android:layout_marginTop="11dp"
android:background="#drawable/image1"
/>
I've got a .png file in my Drawable folder. How do I make it into an Imageview?
imageView.setImageResource(R.drawable.your_drawable);
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="#drawable/my_image"
/>