效果圖,給banner設置圓角,1沒有直接修改imageView而是使用自帶方法進行設置ide
具體方法以下ui
//圓角方法 @TargetApi(Build.VERSION_CODES.LOLLIPOP) public void setClipViewCornerRadius(View view, final int radius) { if (Build.VERSION.SDK_INT < Build.VERSION_CODES.LOLLIPOP) { //不支持5.0版本如下的系統 return; } if (view == null) return; if (radius <= 0) { return; } view.setOutlineProvider(new ViewOutlineProvider() { @Override public void getOutline(View view, Outline outline) { // outline.setRoundRect(20, 20, view.getWidth()-40, view.getHeight()-40, radius); outline.setRoundRect(40, 0, view.getWidth()-40, view.getHeight(), radius);//這是設置圓角的關鍵設置 // Rect rect = new Rect(); // view.getGlobalVisibleRect(rect); // int leftMargin = 40; // int topMargin = 40; // Rect selfRect = new Rect(leftMargin, topMargin, // rect.right - rect.left - leftMargin, rect.bottom - rect.top - topMargin); // outline.setRoundRect(selfRect, 30); } }); view.setClipToOutline(true); }