Android开发时间item连线

2020-08-28  本文已影响0人  你的益达233

需求:ui设置天与天之间用线连起来,线的长度随天内容高度变化,说的有点抽象,

思路:其实有两个RecyclerView和一条线组成,外层一个RecyclerView,外层的item有RecyclerView和一条线组成,里层的RecyclerView的item就是具体某天做的内容

最主要还是用到ConstraintLayout的相关属性,利用View的top,bottom和RecyclerView的top,bottom对齐,自然高度就和RecyclerView一样了

示例布局代码:

<android.support.constraint.ConstraintLayout 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="wrap_content"
android:paddingLeft="16dp"
android:paddingRight="16dp">

<View
    android:id="@+id/view_top_divider"
    android:layout_width="match_parent"
    android:layout_height="20dp"
    app:layout_constraintTop_toTopOf="parent"
    android:visibility="gone"/>

<ImageView
    android:id="@+id/iv_top_dot"
    android:layout_width="18dp"
    android:layout_height="18dp"
    android:scaleType="centerCrop"
    android:src="@mipmap/icon_yuan_study_path"
    app:layout_constraintLeft_toLeftOf="parent"
    app:layout_constraintTop_toBottomOf="@id/view_top_divider" />


<TextView
    android:id="@+id/tv_path_name"
    style="@style/tv_w_w_s16_c_33_bold"
    android:layout_marginLeft="12dp"
    android:singleLine="true"
    app:layout_constraintBottom_toBottomOf="@id/iv_top_dot"
    app:layout_constraintLeft_toRightOf="@id/iv_top_dot"
    app:layout_constraintTop_toTopOf="@id/iv_top_dot"
    tools:text="新手必学"
    android:includeFontPadding="false"/>

<ImageView
    android:id="@+id/iv_show_status"
    android:layout_width="18dp"
    android:layout_height="18dp"
    android:scaleType="centerCrop"
    android:src="@mipmap/zk_icon"
    app:layout_constraintBottom_toBottomOf="@id/iv_top_dot"
    app:layout_constraintRight_toRightOf="parent"
    app:layout_constraintTop_toTopOf="@id/iv_top_dot"
    android:padding="2dp"/>


<View
    android:layout_width="1dp"
    android:layout_height="0dp"
    app:layout_constraintBottom_toBottomOf="@id/rv_all_classify_path"
    app:layout_constraintLeft_toLeftOf="@id/iv_top_dot"
    app:layout_constraintRight_toRightOf="@id/iv_top_dot"
    app:layout_constraintTop_toTopOf="@id/rv_all_classify_path"
    app:layout_goneMarginLeft="18dp"
    android:background="@color/m_red_one"/>

<android.support.v7.widget.RecyclerView
    android:id="@+id/rv_all_classify_path"
    android:layout_width="0dp"
    android:layout_height="wrap_content"
    app:layout_constraintLeft_toLeftOf="@+id/tv_path_name"
    app:layout_constraintTop_toBottomOf="@+id/iv_top_dot"
    app:layout_constraintRight_toRightOf="@id/iv_show_status"
    app:layout_goneMarginLeft="29dp"/>

<View
    android:id="@+id/view_bottom"
    android:layout_width="match_parent"
    android:layout_height="20dp"
    app:layout_constraintTop_toBottomOf="@id/iv_top_dot"
    android:visibility="gone"/>


</android.support.constraint.ConstraintLayout>
布局示意图.png
上一篇下一篇

猜你喜欢

热点阅读