简体   繁体   English

在textviews中的两个可绘制对象之间绘制线

[英]Drawing line between two drawables in the textviews

在此处输入图片说明

I have the issue with drawing line like in a pic above. 我有画线的问题,如上图所示。 How can I do that? 我怎样才能做到这一点? Here's the code of the view, where I need to implement that. 这是视图的代码,我需要在其中实现该代码。 I guess I need to use canvas, but I'm not sure about that. 我想我需要使用画布,但是我不确定。 Thanks for any advice! 感谢您的任何建议!

<RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:layout_marginTop="@dimen/linear_layout_buttons_margin_top"
        android:orientation="vertical">

        <TextView
            android:id="@+id/button_from_city"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="60dp"
            android:layout_marginRight="60dp"
            android:layout_marginTop="4dp"
            android:background="@drawable/button_white"
            android:drawableLeft="@drawable/ic_green"
            android:drawablePadding="@dimen/dots_white_button_padding"
            android:drawableStart="@drawable/ic_green"
            android:gravity="center_vertical"
            android:hint="@string/from_place"
            android:padding="@dimen/dots_white_button_padding"
            android:textColor="@color/color_accent"
            android:textColorHint="@color/text_view_hint_color"/>

        <TextView
            android:id="@+id/button_to_city"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@id/button_from_city"
            android:layout_marginBottom="4dp"
            android:layout_marginLeft="60dp"
            android:layout_marginRight="60dp"
            android:layout_marginTop="4dp"
            android:background="@drawable/button_white"
            android:drawableLeft="@drawable/ic_red"
            android:drawablePadding="@dimen/dots_white_button_padding"
            android:drawableStart="@drawable/ic_red"
            android:gravity="center_vertical"
            android:hint="@string/to_place"
            android:padding="@dimen/dots_white_button_padding"
            android:textColor="@color/color_accent"
            android:textColorHint="@color/text_view_hint_color"/>
    </RelativeLayout>

You can provide two drawable resources for the textviews and set them as drawableStart, based on the required conditions of your work. 您可以根据工作所需条件为文本视图提供两个可绘制资源,并将它们设置为drawableStart。 The point here is using an image which contains a colored circle and a line, which is much simpler than drawing the layout with canvas. 这里的重点是使用包含彩色圆圈和线条的图像,这比使用画布绘制布局要简单得多。

我将简单地在可绘制点的上方和下方添加两个具有1dp宽度灰色背景的视图,并根据项目的位置管理可见性。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM