如何在Android中实现图片下方的垂直虚线?

如何在Android中实现图片下方的垂直虚线?,第1张

概述在不使用任何库的情况下如何实现这种布局?我尝试过类似的 *** 作,但无法获得确切的布局my_layout.xml<?xmlversion="1.0"encoding="utf-8"?><RelativeLayoutxmlns:android="http://schemas.android.com/apkes/android"xmlns:app="http://schemas.android.c

在不使用任何库的情况下如何实现这种布局?

我尝试过类似的 *** 作,但无法获得确切的布局

my_layout.xml

<?xml version="1.0" enCoding="utf-8"?><relativeLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    xmlns:tools="http://schemas.androID.com/tools"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:layout_margintop="20dp"    tools:context=".MainActivity">    <relativeLayout        androID:background="@drawable/layout_border"        androID:layout_margin="20dp"        androID:padding="10dp"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent">        <relativeLayout            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:orIEntation="horizontal">            <ImageVIEw                androID:ID="@+ID/iv_tick"                androID:layout_wIDth="17dp"                androID:layout_height="17dp"                androID:layout_marginleft="20dp"                androID:src="@drawable/tick" />            <TextVIEw                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:layout_alignBaseline="@+ID/iv_tick"                androID:layout_marginleft="14dp"                androID:layout_marginRight="20dp"                androID:layout_toRightOf="@+ID/iv_tick"                androID:linespacingExtra="6dp"                androID:text="This is my text. This is my text. This is my text. This is my text. "                androID:textcolor="#000"                androID:textSize="16dp" />            <ImageVIEw                androID:src="@drawable/dotted_line"                androID:foregroundGravity="left"                androID:layout_below="@+ID/iv_tick"                androID:scaleType="fitXY"                androID:layout_wIDth="match_parent"                androID:layout_height="match_parent"/>        </relativeLayout>        <!--<com.example.myapplication.divIDerVIEw            androID:layout_wIDth="wrap_content"            androID:layout_height="fill_parent"            androID:layerType="software"            androID:color="#ff0000"            androID:orIEntation="vertical"            androID:dashLength="5dp"            androID:dashGap="1dp"            androID:dashThickness="1dp" />-->    </relativeLayout></relativeLayout>

dotted_line.xml

<?xml version="1.0" enCoding="utf-8"?><rotate xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:fromdegrees="90"    androID:todegrees="90">    <shape xmlns:androID="http://schemas.androID.com/apk/res/androID"        androID:shape="line">        <stroke            androID:wIDth="2dp"            androID:color="#ff0000"            androID:dashWIDth="4dp"            androID:dashGap="4dp" />    </shape></rotate>

这是我用上面实现的代码得到的结果.如何获得类似我上面发布的图像的结果?

我什至尝试了约束布局,但也没有帮助.

解决方法:

输出:

用这个 :

<?xml version="1.0" enCoding="utf-8"?><androID.support.design.Widget.CoordinatorLayout xmlns:androID="http://schemas.androID.com/apk/res/androID"    xmlns:app="http://schemas.androID.com/apk/res-auto"    androID:ID="@+ID/main_content"    androID:layout_wIDth="match_parent"    androID:layout_height="match_parent"    androID:background="@color/grey_5"    androID:fitsSystemwindows="true">    <androID.support.v4.Widget.nestedScrollVIEw        androID:ID="@+ID/nested_scroll_vIEw"        androID:layout_wIDth="match_parent"        androID:layout_height="match_parent"        androID:scrollbars="none"        androID:scrollingCache="true"        app:layout_behavior="@string/appbar_scrolling_vIEw_behavior">        <linearLayout            androID:layout_wIDth="match_parent"            androID:layout_height="wrap_content"            androID:descendantFocusability="blocksDescendants"            androID:orIEntation="vertical">            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal">                <relativeLayout                    androID:layout_wIDth="wrap_content"                    androID:layout_height="match_parent"                    androID:layout_marginleft="@dimen/spacing_smlarge"                    androID:layout_marginStart="@dimen/spacing_smlarge"                    androID:gravity="center_horizontal"                    androID:orIEntation="vertical">                    <VIEw                        androID:layout_wIDth="1dp"                        androID:layout_height="match_parent"                        androID:layout_centerHorizontal="true"                        androID:background="@color/grey_10" />                    <ImageVIEw                        androID:layout_wIDth="@dimen/spacing_mIDdle"                        androID:layout_height="@dimen/spacing_mIDdle"                        androID:layout_margintop="@dimen/spacing_large"                        androID:tint="#9CCC65"                        app:srcCompat="@drawable/shape_round_solID" />                </relativeLayout>                <androID.support.v7.Widget.CardVIEw                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:layout_marginBottom="@dimen/spacing_medium"                    androID:layout_marginleft="@dimen/spacing_mIDdle"                    androID:layout_marginRight="@dimen/spacing_mIDdle"                    androID:layout_margintop="@dimen/spacing_mIDdle"                    androID:visibility="visible"                    app:cardCornerRadius="2dp"                    app:cardElevation="1dp">                    <linearLayout                        androID:layout_wIDth="match_parent"                        androID:layout_height="wrap_content"                        androID:orIEntation="vertical">                        <linearLayout                            androID:layout_wIDth="match_parent"                            androID:layout_height="wrap_content"                            androID:layout_marginBottom="@dimen/spacing_medium"                            androID:layout_marginleft="@dimen/spacing_large"                            androID:layout_marginRight="@dimen/spacing_large"                            androID:layout_margintop="@dimen/spacing_large"                            androID:gravity="center_vertical"                            androID:orIEntation="horizontal">                            <TextVIEw                                androID:layout_wIDth="match_parent"                                androID:layout_height="wrap_content"                                androID:gravity="center_vertical"                                androID:text="Taylor W "                                androID:textAppearance="@style/TextAppearance.AppCompat.Caption"                                androID:textcolor="#000"                                androID:textStyle="bold" />                        </linearLayout>                    </linearLayout>                </androID.support.v7.Widget.CardVIEw>            </linearLayout>            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal">                <relativeLayout                    androID:layout_wIDth="wrap_content"                    androID:layout_height="match_parent"                    androID:layout_marginleft="@dimen/spacing_smlarge"                    androID:layout_marginStart="@dimen/spacing_smlarge"                    androID:gravity="center_horizontal"                    androID:orIEntation="vertical">                    <VIEw                        androID:layout_wIDth="1dp"                        androID:layout_height="match_parent"                        androID:layout_centerHorizontal="true"                        androID:background="@color/grey_10" />                    <ImageVIEw                        androID:layout_wIDth="@dimen/spacing_mIDdle"                        androID:layout_height="@dimen/spacing_mIDdle"                        androID:layout_margintop="@dimen/spacing_large"                        androID:tint="#29B6F6"                        app:srcCompat="@drawable/shape_round_solID" />                </relativeLayout>                <androID.support.v7.Widget.CardVIEw                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:layout_marginBottom="@dimen/spacing_medium"                    androID:layout_marginleft="@dimen/spacing_mIDdle"                    androID:layout_marginRight="@dimen/spacing_mIDdle"                    androID:layout_margintop="@dimen/spacing_mIDdle"                    androID:visibility="visible"                    app:cardCornerRadius="2dp"                    app:cardElevation="1dp">                    <linearLayout                        androID:layout_wIDth="match_parent"                        androID:layout_height="wrap_content"                        androID:orIEntation="vertical">                        <linearLayout                            androID:layout_wIDth="match_parent"                            androID:layout_height="wrap_content"                            androID:layout_marginBottom="@dimen/spacing_medium"                            androID:layout_marginleft="@dimen/spacing_large"                            androID:layout_marginRight="@dimen/spacing_large"                            androID:layout_margintop="@dimen/spacing_large"                            androID:gravity="center_vertical"                            androID:orIEntation="horizontal">                            <TextVIEw                                androID:layout_wIDth="match_parent"                                androID:layout_height="wrap_content"                                androID:gravity="center_vertical"                                androID:text="Taylor W "                                androID:textAppearance="@style/TextAppearance.AppCompat.Caption"                                androID:textcolor="#000"                                androID:textStyle="bold" />                        </linearLayout>                    </linearLayout>                </androID.support.v7.Widget.CardVIEw>            </linearLayout>            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal">                <relativeLayout                    androID:layout_wIDth="wrap_content"                    androID:layout_height="match_parent"                    androID:layout_marginleft="@dimen/spacing_smlarge"                    androID:layout_marginStart="@dimen/spacing_smlarge"                    androID:gravity="center_horizontal"                    androID:orIEntation="vertical">                    <VIEw                        androID:layout_wIDth="1dp"                        androID:layout_height="match_parent"                        androID:layout_centerHorizontal="true"                        androID:background="@color/grey_10" />                    <ImageVIEw                        androID:layout_wIDth="@dimen/spacing_mIDdle"                        androID:layout_height="@dimen/spacing_mIDdle"                        androID:layout_margintop="@dimen/spacing_large"                        androID:tint="#FF4081"                        app:srcCompat="@drawable/shape_round_solID" />                </relativeLayout>                <androID.support.v7.Widget.CardVIEw                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:layout_marginBottom="@dimen/spacing_medium"                    androID:layout_marginleft="@dimen/spacing_mIDdle"                    androID:layout_marginRight="@dimen/spacing_mIDdle"                    androID:layout_margintop="@dimen/spacing_mIDdle"                    androID:visibility="visible"                    app:cardCornerRadius="2dp"                    app:cardElevation="1dp">                    <linearLayout                        androID:layout_wIDth="match_parent"                        androID:layout_height="wrap_content"                        androID:orIEntation="vertical">                        <linearLayout                            androID:layout_wIDth="match_parent"                            androID:layout_height="wrap_content"                            androID:layout_marginBottom="@dimen/spacing_medium"                            androID:layout_marginleft="@dimen/spacing_large"                            androID:layout_marginRight="@dimen/spacing_large"                            androID:layout_margintop="@dimen/spacing_large"                            androID:gravity="center_vertical"                            androID:orIEntation="horizontal">                            <TextVIEw                                androID:layout_wIDth="match_parent"                                androID:layout_height="wrap_content"                                androID:gravity="center_vertical"                                androID:text="Taylor W "                                androID:textAppearance="@style/TextAppearance.AppCompat.Caption"                                androID:textcolor="#000"                                androID:textStyle="bold" />                        </linearLayout>                    </linearLayout>                </androID.support.v7.Widget.CardVIEw>            </linearLayout>            <linearLayout                androID:layout_wIDth="match_parent"                androID:layout_height="wrap_content"                androID:orIEntation="horizontal">                <relativeLayout                    androID:layout_wIDth="wrap_content"                    androID:layout_height="match_parent"                    androID:layout_marginleft="@dimen/spacing_smlarge"                    androID:layout_marginStart="@dimen/spacing_smlarge"                    androID:gravity="center_horizontal"                    androID:orIEntation="vertical">                    <VIEw                        androID:layout_wIDth="1dp"                        androID:layout_height="match_parent"                        androID:layout_centerHorizontal="true"                        androID:background="@color/grey_10" />                    <ImageVIEw                        androID:layout_wIDth="@dimen/spacing_mIDdle"                        androID:layout_height="@dimen/spacing_mIDdle"                        androID:layout_margintop="@dimen/spacing_large"                        androID:tint="#F57F17"                        app:srcCompat="@drawable/shape_round_solID" />                </relativeLayout>                <androID.support.v7.Widget.CardVIEw                    androID:layout_wIDth="match_parent"                    androID:layout_height="wrap_content"                    androID:layout_marginBottom="@dimen/spacing_medium"                    androID:layout_marginleft="@dimen/spacing_mIDdle"                    androID:layout_marginRight="@dimen/spacing_mIDdle"                    androID:layout_margintop="@dimen/spacing_mIDdle"                    androID:visibility="visible"                    app:cardCornerRadius="2dp"                    app:cardElevation="1dp">                    <linearLayout                        androID:layout_wIDth="match_parent"                        androID:layout_height="wrap_content"                        androID:orIEntation="vertical">                        <linearLayout                            androID:layout_wIDth="match_parent"                            androID:layout_height="wrap_content"                            androID:layout_marginBottom="@dimen/spacing_medium"                            androID:layout_marginleft="@dimen/spacing_large"                            androID:layout_marginRight="@dimen/spacing_large"                            androID:layout_margintop="@dimen/spacing_large"                            androID:gravity="center_vertical"                            androID:orIEntation="horizontal">                            <TextVIEw                                androID:layout_wIDth="match_parent"                                androID:layout_height="wrap_content"                                androID:gravity="center_vertical"                                androID:text="Taylor W "                                androID:textAppearance="@style/TextAppearance.AppCompat.Caption"                                androID:textcolor="#000"                                androID:textStyle="bold" />                        </linearLayout>                    </linearLayout>                </androID.support.v7.Widget.CardVIEw>            </linearLayout>        </linearLayout>    </androID.support.v4.Widget.nestedScrollVIEw></androID.support.design.Widget.CoordinatorLayout>

在可绘制文件夹名称中创建一个可绘制对象drawable / shape_round_solID

<?xml version="1.0" enCoding="utf-8"?><shape xmlns:androID="http://schemas.androID.com/apk/res/androID"    androID:shape="oval">    <solID androID:color="@color/colorAccent" />    <size        androID:wIDth="15dp"        androID:height="15dp" /></shape>

添加此dimens.xml

<!--genaral spacing--><dimen name="spacing_xsmall">2dp</dimen><dimen name="spacing_small">3dp</dimen><dimen name="spacing_medium">5dp</dimen><dimen name="spacing_xmedium">7dp</dimen><dimen name="spacing_mIDdle">10dp</dimen><dimen name="spacing_large">15dp</dimen><dimen name="spacing_smlarge">18dp</dimen><dimen name="spacing_mlarge">20dp</dimen><dimen name="spacing_mxlarge">25dp</dimen><dimen name="spacing_xlarge">35dp</dimen><dimen name="spacing_xmlarge">40dp</dimen><dimen name="spacing_xxlarge">50dp</dimen><dimen name="spacing_xxxlarge">55dp</dimen><dimen name="appbar_padding_top">8dp</dimen>

希望这对所有人都有效.

总结

以上是内存溢出为你收集整理的如何在Android中实现图片下方垂直虚线?全部内容,希望文章能够帮你解决如何在Android中实现图片下方的垂直虚线?所遇到的程序开发问题。

如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。

欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/web/1081727.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-27
下一篇 2022-05-27

发表评论

登录后才能评论

评论列表(0条)

保存