android时间轴高度动态显示问题

关于android时间轴的实现,网上有很多教程,在此不做仔细探讨,可参考一下链接

1.Android时间轴的实现

2.android 时间轴 (可动态添加时间轴的内部内容,没实现删除功能)


在此主要是解决一个问题,当我们的item的高度不固定,即item的高度是根据内容动态调整时,时间轴的显示问题。

如果我们的时间轴的父布局就是item的根布局(如下所示)

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="#ffffff"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/image"
        android:layout_width="15dp"
        android:layout_height="15dp"
        android:layout_marginLeft="85dp"
        android:src="@drawable/point2" />

	<!--这是时间轴的线-->
    <View
        android:id="@+id/line_normal"
        android:layout_width="3dp"
        android:layout_height="match_parent"	//①时间轴高度
        android:layout_below="@+id/image"
        android:layout_marginLeft="91dp"
        android:background="@color/colorAccent" />

</RelativeLayout>


若我们将<View/>的高度设置为充满父布局,如①处所示,无论父布局的高度是match_parent还是wrap_content,时间轴线均不会显示出来,但是如果我们指定<View/>的高度,则就实现不了内容动态调整时,使时间轴连续。

所以,如果我们想要实现高度动态调整时,可以将时间轴线和圆点放进一个父布局里面,再将他们的父布局放进item里面,如下所示

<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal">

    <RelativeLayout
        android:layout_width="wrap_content"
        android:layout_height="match_parent"		//②时间线以及圆点的父布局的高度充满item
		>		

        <View
            android:id="@+id/time_line"
            android:layout_width="@dimen/dimen_2_dp"
            android:layout_height="match_parent"			//①时间线的高度充满父布局
            android:layout_marginLeft="@dimen/dimen_7_dp"
            android:background="@color/grey" />

        <ImageView
            android:id="@+id/iv_status_icon"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:layout_marginTop="@dimen/dimen_6_dp"
            android:src="@drawable/note_complete" />

    </RelativeLayout>
	
    <!--右边写其他控件-->
</LinearLayout>


这样,就可以实现当item高度动态调整时,时间线也可以动态调整并且连续了

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值