How to draw a line between two buttons in android?

大憨熊 提交于 2020-01-02 11:34:47

问题


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

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:


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"
    />


来源:https://stackoverflow.com/questions/11258756/how-to-draw-a-line-between-two-buttons-in-android

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