java region是什么?讓我們一起來了解一下吧!
Java region是區域,它表示的是canvas圖層上的某一塊完全封閉的區域。在很多情況下,我們會利用Region來構造一個圖形。Region有public Region(Regionregion)等構造方法。
Region的構造方法有以下幾個:
public?Region(Region?region);//復制一個Region public?Region(Rect?r);//通過Rect構建一個Region public?Region(int?left,?int?top,?int?right,?int?bottom);//通過坐標點構建一個region
實戰演練,具體步驟如下所示:
?????//設置畫筆 ????????Paint?paint=new?Paint(); ????????paint.setColor(getRidColor(R.color.color_0a900a)); ????????paint.setStyle(Paint.Style.FILL); ????????paint.setStrokeWidth(5f);//無描邊,設置setStrokeWidth無效 ? ????????//構建矩形 ????????Rect?rect=new?Rect(); ????????rect.set(340,50,740,250); ????????Region?region=new?Region(rect); ? ????????//Android還提供了一個RegionIterator來對Region中的所有矩陣進行迭代, ????????//?可以使用該類,獲得某個Region的所有矩陣 ????????//通過遍歷region中的矩陣,并繪制出來,來繪制region ????????RegionIterator?iterator=new?RegionIterator(region); ???????Rect?r=new?Rect(); ????????while(iterator.next(r)){ ????????????canvas.drawRect(r,paint); ????????}
Region空構造函數:
public?Region();
包含的set函數有:
public?void?setEmpty();//設置空 public?boolean?set(Region?region); public?boolean?set(Rect?r); public?boolean?set(int?left,?int?top,?int?right,?int?bottom); public?boolean?setPath(Path?path,?Region?clip);
以上就是小編今天的分享了,希望可以幫助到大家。