问题
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