-1
我想在我的自定義視圖中剪輯路徑,但它顯示爲黑色。通過搜索找到相同的原因。發現我需要設置「setLayerType(LAYER_TYPE_SOFTWARE,null)
」。在此之後,它看起來很完美,但在一些設計中崩潰。ClipPath與setLayerType作爲軟件崩潰
崩潰日誌(其中一個基於設備):
- java.lang.NegativeArraySizeException
位圖超過32位
public class CardLayout extends LinearLayout { private View mRoot; private ImageView mCategoryImageView; private LinearLayout mCategoryBottomView; private RectF mRect; private Paint mPaint; private View mDivider; private Path mPath; private int mPadding = 30; public CardLayout(Context context) { super(context); } public CardLayout(Context context, AttributeSet attrs, int defStyleAttr) { super(context, attrs, defStyleAttr); } public CardLayout(Context context, AttributeSet attrs) { super(context, attrs); mContext = context; mRoot = LayoutInflater.from(getContext()).inflate(R.layout.card_content, null); addView(mRoot); initUI(); } private void initUI() { mPaint = new Paint(Paint.ANTI_ALIAS_FLAG); mPaint.setXfermode(new PorterDuffXfermode(PorterDuff.Mode.CLEAR)); mPath = new Path(); mCategoryHeadlineTextView = (TextView) mRoot.findViewById(R.id.categoryHeadline); mCategoryImageView = (ImageView) mRoot.findViewById(R.id.categoryImageView); mCategoryBottomView = (LinearLayout) mRoot.findViewById(R.id.ctg_btm_view); mDivider = mRoot.findViewById(R.id.divider); setLayerType(LAYER_TYPE_SOFTWARE,null); } public void setCategoryImage(String categoryUrl) { if (mCategoryImageView != null) { Glide.with(mContext) .load(categoryUrl) .placeholder(R.drawable.two) .into(mCategoryImageView); } } public void setBottomView(String[] optionText, int[] optionResource, int tag) { if (mCategoryBottomView != null) { CategoryBottomOptions options = new CategoryBottomOptions(mContext, optionText, optionResource, tag, mCategoryBottomView); } } @Override protected void dispatchDraw(Canvas canvas) { super.dispatchDraw(canvas); mRect = new RectF(mDivider.getX() - mPadding, mDivider.getY() - mPadding, mDivider.getX() + mPadding, mDivider.getY() + mPadding); mPath.addArc(mRect, 270, 180); canvas.clipPath(mPath); canvas.drawPath(mPath, mPaint); mRect = new RectF(mDivider.getWidth() - mPadding, mDivider.getY() - mPadding, mDivider.getWidth() + mPadding, mDivider.getY() + mPadding); mPath = new Path(); mPath.addArc(mRect, 90, 180); canvas.clipPath(mPath); canvas.drawPath(mPath, mPaint); } }
你是救星..謝謝你的工作。 :) – Niveditha