Sudden Issue in setting image border - android

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 .

Related

Using Glide Library: How to set camera icon on the right side of a profile image?

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"/>

Glide Android - Doesn't show all the image

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.

Android. ImageButton, stretch background and center src

I have a ImageButton with 2 images
What I need from this imagebutton if having the backgrounf image to stretch, etc the src image to be centered in the stretched button)
The background image(textured gray) to stretch between 2 ImageButton
The src image("Title") to be centered on this button.
Still 2 problems:
1- Background stretch seem to work, but only if I replace layout_width="wrap_content" with layout_width="fill_parent", BUT, the button doesn't from before the other button.
2- even with fill parent, i get the src image also stretched.
Suggestions welcome!
xml:
<ImageButton android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnListviewHeader_Title"
android:background="#drawable/a_btn_sort_title"
android:onClick="listView_FilterBy_Title"
android:nestedScrollingEnabled="true"
android:adjustViewBounds="true"
android:scaleType="fitXY"
android:layout_alignBottom="#+id/btnListviewHeader_Number"
android:cropToPadding="true"
android:src="#drawable/a_btn_sort_title_en"
android:layout_alignTop="#+id/btnListviewHeader_Number"
android:layout_toLeftOf="#+id/btnListviewHeader_Fav"
android:layout_toRightOf="#+id/btnListviewHeader_Number"
android:layout_toEndOf="#+id/btnListviewHeader_Number" />
Finally found my answer:
1- ImageButton between 2 ImageButton = remove: "android:layout_toEndOf="#+id/btnListviewHeader_Number""
2- Src centered: android:scaleType="fitCenter"
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/btnListviewHeader_Title"
android:background="#drawable/a_btn_sort_title"
android:onClick="listView_FilterBy_Title"
android:nestedScrollingEnabled="true"
android:adjustViewBounds="true"
android:scaleType="fitCenter"
android:layout_alignBottom="#+id/btnListviewHeader_Number"
android:cropToPadding="true"
android:src="#drawable/a_btn_sort_title_en"
android:layout_alignTop="#+id/btnListviewHeader_Number"
android:layout_toLeftOf="#+id/btnListviewHeader_Fav"
android:layout_toRightOf="#+id/btnListviewHeader_Number" />
Hope it help someone :)

How to dynamically replay the image source for an image button in android

I have an image button with the following xml:
<ImageButton
android:id="#+id/imageButton1"
android:contentDescription="#string/button_click1"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_margin="20dp"
android:src="#drawable/button_default" />
Now I want to dynamically change the image source from loading a file. I know the right way is to use
this.button.setImageDrawable(this.default_source);
The problem is I want to make sure two things:
1. The new image should be in the same place as before replacing.
2. If the newly loaded image is not 200dp * 100dp, I want automatically scale the
image not cutting it. Any idea how to do this?
Thanks a lot!!!
Put the following xml attribute into your ImageButton xml...
android:scaleType="fitXY"
as below...
<ImageButton
android:id="#+id/imageButton1"
android:contentDescription="#string/button_click1"
android:layout_width="200dp"
android:layout_height="100dp"
android:layout_margin="20dp"
android:scaleType="fitXY"
android:src="#drawable/button_default" />

Remove white border around an ImageView

My designer keeps adding a little padding around my image.
I want the image the stick on the top and to fill out the width of the screen.
Here's a screenshot from the designer:
This is my XML code:
<ImageView
android:id="#+id/markertap_header"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/header_bootsverleih_xhdpi" />
It looks like the image is larger than the screen width, so it's getting scaled down after sizing. Try adding android:adjustViewBounds="true" to your ImageView.
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:adjustViewBounds="true"
android:id="#+id/imageView"
android:cropToPadding="false"
android:scaleType="fitXY" />
Experienced the same when I used an ImageView for Splashscreen, this^ worked for me.
you might want to add it your image view only this.
It fixed my problem.
android:paddingVertical="0dp"
android:paddingHorizontal="0dp"

Categories

Resources