简体   繁体   中英

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. 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宽度灰色背景的视图,并根据项目的位置管理可见性。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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