0

這裏是我的屏幕布局的快速說明。圍繞自定義LinearLayout繪製邊框

<CustomLayout> 
    <CardView> 
     <CustomTextView /> 
     <CustomTextView /> 
     <CustomTextView /> 
    </CardView> 
    <CustomTextView /> 
    <CustomTextView /> 
</CustomLayout> 

我編碼它,以便CardView extends LinearLayoutCustomTextView extends TextView。除非我想在CardView的底部和第二個CustomTextView的底部繪製邊框線,否則一切正常。要做到這一點,我用同樣的方法對我CardView和我CustomTextView

@Override 
protected void onDraw(Canvas canvas) { 
    super.onDraw(canvas); 
    getLocalVisibleRect(mRect); 
    if (mDrawBottomBorder) 
     canvas.drawLine(mRect.left, mRect.bottom, mRect.right, mRect.bottom, mBorderPaint); 
} 

該方法被調用在這兩種情況下,即對我CardViewCustomTextView但它並不繪製邊框爲我CardView!我懷疑這是因爲它extends LinearLayout而不是TextView,但它不應該工作嗎?

回答

0

好吧我想通了。我的第三個CustomTextView在我的CardView佈局中覆蓋了它下面的邊界,因此線條不可見。