Whats the different between srcCompat and background in an ImageView/ImageButton - android

I have an ImageView in a RelativeLayout. The background of the ImageView is empty and the srcCompat is linked to my image in the drawable folder. In the layout Preview everything looks fine but when I test the app in an emulator or real smartphone my ImageView is empty and I can't see the selected Image. When I link the background property to my image in the drawable folder and delete the entry from srcCompat my picture is shown by the app. The problem is I can't scale the image if its set as the background of my ImageView. Can someone help me?
Thanks and sorry for my bad english!

The difference is that srcCompatis the actual content of your ImageView. You can, for example set backgroundColor to red, and give a drawable to your srcCompat. The result will be a red background and the given drawable above it.
Hope this helps.

Use src in place of srcCompat.As it srcCompat attribute is actually defined within AppCompat library. For more details

Related

How to change size of resource icon in button using FancyButtons library?

Is there is a way to change size of resource icon in button created with FancyButtons library https://github.com/medyo/Fancybuttons ?
In the documentation I see only how to change size of font icon.
My icon is raster png, so I can`t convert it to svg and font icon properly.
Thank you in advance.
Found answer here.
It can be done programmatically:
mFbWeiXinLogin.setIconResource(R.drawable.umeng_socialize_wechat);
mFbWeiXinLogin.setIconPosition(FancyButton.POSITION_LEFT);
mFbWeiXinLogin.getIconImageObject().setLayoutParams(new LinearLayout.LayoutParams(50, 50));
put Icon in the drawable folder and then use like this :
fancy:fb_iconResource="#drawable/instagram"
visit this for more detail https://github.com/medyo/Fancybuttons/tree/master/samples
In this project you got the idea to perform this.

How to fill the drawable region in an imageView with another drawable?

so I'm trying to find the region of the current image in the ImageView and fill that region with a different image. Here is the original image Empty Circle inside an imageView. The imageView has a drawable of a circle inside. Then I'm trying to make it into something like this Circle filled with image inside an ImageView when a user chooses an image. I don't want to manually Photoshop a circle image. I am just hoping to fill the region with another image. I have tried SRC_IN method from AlphaComposite, but for android, I can't convert from BitMap to graphics2D. If anyone knows how to solve this using the BitmapFactory in android, I would really appreciate your help. Thank you.
The other solution besides Bitmaps, may be too simple for whatever you are trying to achieve otherwise I think it would have occurred to you. I'm just pointing it out in case you have "code blindness" and are trying to over-engineer the solution because you've worked on it for too long (we've all done it)
It is to have that circle/shape image saved as a png with the area you want filled being transparent then set it as the drawable for an ImageView (etc.) then in a RelativeLayout lay this view over the image you want to fill the area and apply a transparent background to the shape view OR simply set the fill image as the background for the shape view.

How to use same Android drawable to all resolutios

I have one big image named panel_bck.jpg to use in different resolutions to decrease apk size. The image format is JPG and it's size is 1.9MB. I put it to default drawable folder only. But when I set the background in code, the BitmapFactory can't find the image at
drawable/panel_bck.jpg
and the result is all black background. I tested this case with other images(PNG files, JPG files) and there is no problem with them. Only question is that a limitation exist for the drawable size or what is the problem? How can I solve this?
If your image very big resoulation you will set drawable-xxhdpi directory only.
I had a problem like yours trying to maka a big image fit into a too small ImageView and I fixed my problem by using this line in the layout xml file:
android:adjustViewBounds="true"
I don't know if it can ba applied to an activity background though.
You should use 9patch image. You can create 9patch image by using the tool called draw9patch located in sdk/tools. First create a large resolution image and give to draw9patch it will create a 9patch image with extension .9.png add that image in drawable it will solve you problem.
See following links for detail
http://developer.android.com/tools/help/draw9patch.html
http://codesignature.com/how-to-design-9-patch-buttons-for-android-using-adobe-photoshop-for-all-pixel-densities-and-states/

set new Image on ImageView

I created an XML layout for my project with an ImageView in it. I add a default image for imageView. Now programatically I am getting that imageview and trying to change the image source using imgView.setImageBitmap(newbitmap);.
The problem is that both images are showing - the default image displays behind programatically added one.
I tried:
imgView.setImageResource(0);
imgView.setImageDrawable(null);
imgView.setAlpha(0);
imgView.setImageBitmap(null);
...but the default image is still visible.
If you are setting the background of the ImageView in the xml file, then it will remain until you clear the background. ImageView is odd in that it can display two images, background and source. Use the attribute android:src to set the source image and 'android:background' to set the background. All the methods you described will replace the source image but keep the background unchanged.

android cropping drawable

I have a small project in which i download images from internet in the form of drawable and use them in Imageview for which i have provided functionality similar to an Imagebutton but without the gray edges.
The question is that is there any functionality in Android(similar to iphone) by which we can crop the drawable from edges to make them rounded edged drawable...
Even if its a "not-tested-neither-recommended" method, do let me know... i would like to work on this a bit... thanx in advance folks...
I believe this is probably the link you're looking for: How should I give images rounded corners in Android?
I tried doing it with a drawable and nested and elements, but wasn't able to get the image drawable to show properly. Not sure if there's a way to get this working or not.

Categories

Resources