ICode9

精准搜索请尝试: 精确搜索
首页 > 其他分享> 文章详细

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

2019-11-08 06:34:34  阅读:186  来源: 互联网

标签:android-layout layout ui-design android android-constraintlayout


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

enter image description here

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

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>

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

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

enter image description here

解决方法:

输出:

Check preview

用这个 :

<?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-layout,layout,ui-design,android,android-constraintlayout
来源: https://codeday.me/bug/20191108/2006198.html

本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享;
2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关;
3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关;
4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除;
5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。

专注分享技术,共同学习,共同进步。侵权联系[81616952@qq.com]

Copyright (C)ICode9.com, All Rights Reserved.

ICode9版权所有