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

时间:2016-01-25 08:50:54

标签: android listview android-arrayadapter

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

enter image description here

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

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长度,以秒为单位。

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

1 个答案:

答案 0 :(得分:1)

颜色贴图,你可以使用LinearLayout.Because LinearLayout中的组件有一个属性&#34; layout_weight&#34;。就像这样:

Caused by: java.lang.OutOfMemoryError: Java heap space
    at java.lang.StringCoding$StringDecoder.decode(StringCoding.java:149) ~[na:1.8.0_51]
    at java.lang.StringCoding.decode(StringCoding.java:193) ~[na:1.8.0_51]
    at java.lang.String.<init>(String.java:414) ~[na:1.8.0_51]
    at java.lang.String.<init>(String.java:479) ~[na:1.8.0_51]
    at com.netflix.zuul.http.HttpServletRequestWrapper.parseRequest(HttpServletRequestWrapper.java:167) ~[zuul-core-1.0.28.jar:na]
    at com.netflix.zuul.http.HttpServletRequestWrapper.getInputStream(HttpServletRequestWrapper.java:225) ~[zuul-core-1.0.28.jar:na]
    at javax.servlet.ServletRequest$getInputStream$1.call(Unknown Source) ~[na:na]
    at SimpleHostRoutingFilter.j(SimpleHostRequest.groovy:318) ~[spider.jar:na]
    at SimpleHostRoutingFilter$getRequestBody$2.callCurrent(Unknown Source) ~[na:na]
    at SimpleHostRoutingFilter.run(SimpleHostRequest.groovy:175) ~[spider.jar:na]
    at com.netflix.zuul.ZuulFilter.runFilter(ZuulFilter.java:112) ~[zuul-core-1.0.28.jar:2.4.4]
    at com.netflix.zuul.FilterProcessor.processZuulFilter(FilterProcessor.java:197) ~[zuul-core-1.0.28.jar:2.4.4]
    at com.netflix.zuul.FilterProcessor.runFilters(FilterProcessor.java:161) ~[zuul-core-1.0.28.jar:2.4.4]
    at com.netflix.zuul.FilterProcessor.route(FilterProcessor.java:120) ~[zuul-core-1.0.28.jar:2.4.4]
    at com.netflix.zuul.ZuulRunner.route(ZuulRunner.java:84) ~[zuul-core-1.0.28.jar:2.4.4]
    at com.netflix.zuul.http.ZuulServlet.route(ZuulServlet.java:111) ~[zuul-core-1.0.28.jar:na]
    at com.netflix.zuul.http.ZuulServlet.service(ZuulServlet.java:77) ~[zuul-core-1.0.28.jar:na]