您好,登錄后才能下訂單哦!
這篇文章主要講解了“Java怎么使用處理視圖圓角和色彩的工具類”,文中的講解內容簡單清晰,易于學習與理解,下面請大家跟著小編的思路慢慢深入,一起來研究和學習“Java怎么使用處理視圖圓角和色彩的工具類”吧!
public class DrawCorner { /* * 默認繪制圓角函數,背景白色,半徑20 * */ public static GradientDrawable drawCorner() { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(20); drawable.setColor(Color.WHITE); return drawable; } /* * 默認繪制圓角函數,背景白色 * 參數: * radius:圓角半徑 * */ public static GradientDrawable drawCorner(int radius) { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(radius); drawable.setColor(Color.WHITE); return drawable; } /* * 默認繪制圓角函數,背景白色 * 參數: * radii:四個圓角半徑,依次是左上x、左上y、右上x、右上y、右下x、右下y、左下x、左下y * */ public static GradientDrawable drawCorner(float[] radii) { if (radii == null || radii.length != 8) { radii = new float[]{0, 0, 0, 0, 0, 0, 0, 0}; } GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadii(radii); drawable.setColor(Color.WHITE); return drawable; } /* * 默認繪制圓角函數 * 參數: * radius:圓角半徑 * color:背景色 * */ public static GradientDrawable drawCorner(int radius, int color) { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(radius); drawable.setColor(color); return drawable; } /* * 默認繪制圓角函數 * 參數: * radii:四個圓角半徑,依次是左上x、左上y、右上x、右上y、右下x、右下y、左下x、左下y * color:背景色 * */ public static GradientDrawable drawCorner(float[] radii, int color) { if (radii == null || radii.length != 8) { radii = new float[]{0, 0, 0, 0, 0, 0, 0, 0}; } GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadii(radii); drawable.setColor(color); return drawable; } /* * 默認繪制圓角函數 * 參數: * radius:圓角半徑 * colors:漸變背景色 * */ public static GradientDrawable drawCorner(int radius, int[] colors) { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(radius); drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); drawable.setColors(colors); return drawable; } /* * 默認繪制圓角函數 * 參數: * radii:四個圓角半徑,依次是左上x、左上y、右上x、右上y、右下x、右下y、左下x、左下y * colors:漸變背景色 * */ public static GradientDrawable drawCorner(float[] radii, int[] colors) { if (radii == null || radii.length != 8) { radii = new float[]{0, 0, 0, 0, 0, 0, 0, 0}; } GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadii(radii); drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); drawable.setColors(colors); return drawable; } /* * 默認繪制圓角函數 * 參數: * radius:圓角半徑 * colors:漸變背景色 * orientation:漸變類型( 0:上到下,1:右上到左下,2:右到左,3:右下到左上,4:下到上,5:左下到右上,6:左到右,7:左上到右下 ) * */ public static GradientDrawable drawCorner(int radius, int[] colors, int orientation) { GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadius(radius); drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); switch (orientation) { case 0: drawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM); break; case 1: drawable.setOrientation(GradientDrawable.Orientation.TR_BL); break; case 2: drawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT); break; case 3: drawable.setOrientation(GradientDrawable.Orientation.BR_TL); break; case 4: drawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP); break; case 5: drawable.setOrientation(GradientDrawable.Orientation.BL_TR); break; case 6: drawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); break; case 7: drawable.setOrientation(GradientDrawable.Orientation.TL_BR); break; } drawable.setColors(colors); return drawable; } /* * 默認繪制圓角函數 * 參數: * radii:四個圓角半徑,依次是左上、右上、右下、左下 * colors:漸變背景色 * orientation:漸變類型( 0:上到下,1:右上到左下,2:右到左,3:右下到左上,4:下到上,5:左下到右上,6:左到右,7:左上到右下 ) * */ public static GradientDrawable drawCorner(float[] radii, int[] colors, int orientation) { if (radii == null || radii.length != 8) { radii = new float[]{0, 0, 0, 0, 0, 0, 0, 0}; } GradientDrawable drawable = new GradientDrawable(); drawable.setCornerRadii(radii); drawable.setGradientType(GradientDrawable.LINEAR_GRADIENT); switch (orientation) { case 0: drawable.setOrientation(GradientDrawable.Orientation.TOP_BOTTOM); break; case 1: drawable.setOrientation(GradientDrawable.Orientation.TR_BL); break; case 2: drawable.setOrientation(GradientDrawable.Orientation.RIGHT_LEFT); break; case 3: drawable.setOrientation(GradientDrawable.Orientation.BR_TL); break; case 4: drawable.setOrientation(GradientDrawable.Orientation.BOTTOM_TOP); break; case 5: drawable.setOrientation(GradientDrawable.Orientation.BL_TR); break; case 6: drawable.setOrientation(GradientDrawable.Orientation.LEFT_RIGHT); break; case 7: drawable.setOrientation(GradientDrawable.Orientation.TL_BR); break; } drawable.setColors(colors); return drawable; } }
感謝各位的閱讀,以上就是“Java怎么使用處理視圖圓角和色彩的工具類”的內容了,經過本文的學習后,相信大家對Java怎么使用處理視圖圓角和色彩的工具類這一問題有了更深刻的體會,具體使用情況還需要大家實踐驗證。這里是億速云,小編將為大家推送更多相關知識點的文章,歡迎關注!
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。