How to make an ImageView with rounded corners?

前端 未结 30 2601
天涯浪人
天涯浪人 2020-11-21 05:39

In Android, an ImageView is a rectangle by default. How can I make it a rounded rectangle (clip off all 4 corners of my Bitmap to be rounded rectangles) in the ImageView?

30条回答
  •  一个人的身影
    2020-11-21 06:31

    This pure xml solution was good enough in my case. http://www.techrepublic.com/article/pro-tip-round-corners-on-an-android-imageview-with-this-hack/

    EDIT

    Here's the answer in a nutshell:

    In the /res/drawable folder, create a frame.xml file. In it, we define a simple rectangle with rounded corners and a transparent center.

    
    
         
         
         
         
    
    

    In your layout file you add a LinearLayout that contains a standard ImageView, as well as a nested FrameLayout. The FrameLayout uses padding and the custom drawable to give the illusion of rounded corners.

    
    
        
    
        
    
            
    
            
    
        
    
    
    

提交回复
热议问题