Android: the easiest picture round corner production (card layout)

In APP, pictures are often designed with rounded corners and are very beautiful.
However, it is found that the actual operation is more complicated by looking up the information, and there are roughly two methods.
The first is very complicated: modify the shape of the picture in the JAVA code, the code is difficult to write and lengthy.
The second is funny: a transparent View is used to cover the four corners of the picture, which is a bit self-deceptive. If the equipment is not compatible, the small actions are directly exposed.

Suddenly thought of the third and easiest method, using the CardView component.
How to import CardView dependencies, see my last blog post Android: Installation and use of the latest version of CardView

Just add the attribute
app:cardCornerRadius="16dp"
, the four corners of the card will become round

Take a look at the effect: Insert picture description here
Note: For pictures, the xml preview will not be displayed directly (at first I thought there was a problem with my cardview), and the effect can be seen using the simulator preview.

More interesting projects and techniques are available on my WeChat public account "I have a plan", which contains easter eggs, waiting to be explored~
Insert picture description here

Guess you like

Origin blog.csdn.net/qq1198768105/article/details/114794193