Good day everyone. There was a question: png images come to me from the server, I download and store them on the device. When displaying them in the ImageView, I need to round the edges around this image. Googled for a long time, I was looking for similar tasks, but I didn’t really find anything, so I came out with such a question. Maybe there are examples? Thank you in advance!

1 answer 1

All similar tasks: round the edges, add fog in the center, place in a circle, set a gray-brown-crimson frame in the form of hearts, and so on. are solved in approximately the same way:

  1. Create your own class that inherits from the base class of the widget class MyImageView extends ImageView
  2. Overload the protected void onDraw(Canvas canvas) method - that is, draw our / your hearts in this place
  3. In some cases, when hearts especially perverted will have to be rewritten onMeasure() method - to correctly calculate the size of hearts.
  4. In principle, you can set your public methods to set the level of crimson hearts - setHeartColor() , then you have to declare the attributes of these methods in the res / values ​​/ attrs.xml file, in this case you can directly set the heart color in the XML resource:

 <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:heart="http://schemas.android.com/apk/res/mypackage.heart" android:layout_width="wrap_content" android:layout_height="match_parent" <mypackage.HeartImageView android:id="@+id/myHeart" android:src="@drawable/darling" android:layout_width="wrap_content" android:layout_height="match_parent" heart:heartColor=" @color /light_magenta" /> </LinearLayout> 

In general, Android provides for this almost unlimited possibilities.

  • Thank! But how to solve such a problem, for example: there are three pictures, you need to take a third of each into one and place it in the ImageView. That is, how to make one of three Bitmap objects? - vanyamelikov
  • 1 question = 1 answer - Barmaley