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布局中覆盖了它下面的边界,因此线条不可见。