How to draw a line between two buttons in android?

2019-05-23 17:50发布

I have two buttons in my xml layout as shown bellow.

enter image description here

I used an activity for this button click. I want to draw a line between these buttons as shown. Could someone please help me to draw the line between this by using code or XML..

1条回答
倾城 Initia
2楼-- · 2019-05-23 18:33

You can use an custom view to draw the line such as LineView and override the onDraw.

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

Then use the XML to achieve the layout you want.

<com.android.drawable.LineView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_toRightOf="@id/leftButton"
    android:layout_toLeftOf="@id/rightButton"
    android:layout_below="@id/leftButton"
    android:layout_above="@id/rightButton"
    />
查看更多
登录 后发表回答