Android 列表视图的自定义项适配器

Android custom item adapter for list view

我想创建一个在列表视图中显示时看起来像这样的项目适配器:

我想用来创建它的数据模型如下所示:

TrainingProgram
   - name: String
   - intervals: Array<TrainingInterval>

TrainingInterval
   - intensityType: Enum {WarmUp, Low, Medium, High, CoolDown}
   - durationInSeconds: Int

现在我想的布局是这样的:

RelativeLayout
   - programTitle: TextView - set to top left
   - totalTime: TextView - set to top right
   - colorMap: ImageView - set to bottom and with fill parent horizontally

当我想创建那个颜色图时,我的问题就开始了,颜色根据 TrainingInterval 的长度(以秒为单位)具有不同的宽度。

如何从上述模型开始创建该颜色图?

颜色图,可以使用LinearLayout.BecauseLinearLayout中的组件有一个属性"layout_weight"。像这样:

<LinearLayout
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="horizontal">
    <ImageView
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
    />
    <ImageView
      android:layout_width="0dp"
      android:layout_height="wrap_content"
      android:layout_weight="1"
    />
</LinearLayout>