Draw a semicircle in the background of a View

后端 未结 4 1434
别跟我提以往
别跟我提以往 2020-12-01 03:24

I am trying to create a TextView whose background is a half circle. I create a oval using a ShapeDrawable. I tried to create a semicircle by using ScaleDrawable to double th

4条回答
  •  广开言路
    2020-12-01 03:41

    To clip the oval shape, just embed it in a ClipDrawable like this:

    res/drawable/semicircle.xml

    
    
        
            
        
    
    

    ClipDdrawable common purpose is to create custom progress bars. It clips a part of its content and progressively displays it when its "level" property increases in a range of [0; 10000] (0=hidden, 10000=fully displayed).

    • clipOrientation is the orientation of the clipping progress.
    • gravity is the clipping progress start edge/side.

    To get a half circle, set this ClipDrawable as your view background, and programmatically tweak its "level":

    //...
    findViewById(R.id.my_view).getBackground().setLevel(5000)
    //...
    

    Works on all Android versions ("Added in API level 1") and requires no custom view.

    ;-)

提交回复
热议问题