时间轴 TimeLine线高度自适应问题

最近在做项目的时候,要实现一种时间轴那种效果的样式,大概样子是这样的:

《时间轴 TimeLine线高度自适应问题》 xiaoguo.png

界面有点丑哈,但是效果大概是那样的,然后左边那条线的长度会根据内容的变化而变化,就是自适应。而这次问题的难点就难在那根线上了。

就是我不知道该怎么测量这个内容的高度,从而去确定线的高度,因为我们知道要测量控件的高度是一件非常麻烦的事情,而且在这里这么小的东西,没必要弄很复杂的东西。

后来查询资料,找到一种特别简单的方法去弄。就是我们要把这个线和内容分为左右两部分,左边部分的高度设置为match_parent,右边设置为自适应,整体使用listview,看下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:background="#ffffff"
    android:orientation="horizontal" >

    <RelativeLayout
        android:layout_width="6dp"
        android:layout_height="fill_parent"
        android:layout_marginTop="10dp" >

        <View
            android:id="@+id/line"
            android:layout_width="6dp"
            android:layout_height="match_parent"
            android:background="#ff0000" />
    </RelativeLayout>

    <LinearLayout
        android:layout_marginTop="10dp"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_marginLeft="15dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/tvAcceptStation"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="今天天气不太好,我出去玩了,外面天气不好,我就觉着外面有雾霾"
            android:textSize="17dp" />
    </LinearLayout>

</LinearLayout>

这样一来的话,线的高度就会根据内容自适应啦,问题解决。

    原文作者:糖葫芦_倩倩
    原文地址: https://www.jianshu.com/p/80569056b7c7
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞