Diagonal line across view

喜欢而已 提交于 2019-12-05 18:26:54

Custom view for diagonal line is:

import android.content.Context;
import android.content.res.Resources;
import android.graphics.Canvas;
import android.graphics.Paint;
import android.util.AttributeSet;
import android.view.View;
public class DiagonalLineView extends View {

private int dividerColor;
private Paint paint;

public DiagonalLineView(Context context)
{
    super(context);
    init(context);
}

public DiagonalLineView(Context context, AttributeSet attrs)
{
    super(context, attrs);
    init(context);
}

public DiagonalLineView(Context context, AttributeSet attrs, int defStyle)
{
    super(context, attrs, defStyle);
    init(context);
}

private void init(Context context)
{
    Resources resources = context.getResources();
    dividerColor = resources.getColor(R.color.grey);

    paint = new Paint();
    paint.setAntiAlias(true);
    paint.setColor(dividerColor);
         paint.setStrokeWidth(resources.getDimension(R.dimen.vertical_divider_width));
}

@Override
protected void onDraw(Canvas canvas)
{
    super.onDraw(canvas);
    canvas.drawLine(0, getHeight(), getWidth(), 0, paint);
}

}

It worked for me.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!