如何在每个ListView行上显示左侧彩色边框?

时间:2017-04-15 22:42:25

标签: java android listview colors border

如何在每个ListView行上仅显示左侧彩色边框?

我有5度的用户信誉度表,我想在每个列表视图行的左边界显示相应的颜色。

喜欢这个link

谢谢你们!

3 个答案:

答案 0 :(得分:1)

您可以将面板添加到应用的最左侧部分。在该面板中,您可以放置​​一个预定义的温度计图像。你只有5个级别,对吗?一旦值发生变化 - 选择相应的温度计读数图像并重绘gui元素。

答案 1 :(得分:1)

[1行应为水平ListView,并在开头包含此内容,作为第一个子项,后跟TextView:

LinearLayout

<View android:id="@+id/reputationColor" android:layout_width="4dp" //Aproximately the size from your image android:layout_height="36dp" //About the size of a List Row, but less, as seen in your image android:layout_gravity="top" /> 您需要CustomAdapter,您可以在here

中找到完整示例

在CustomAdapter中,您可以使用

以编程方式设置颜色
ListView

有关CustomAdapter的更多信息,请访问以下网站:

答案 2 :(得分:1)

最简单的方法是在商品布局中创建一个虚拟View。这样,将布局绑定到数据时,您可以轻松更改背景的颜色。像这样:

item_list_layout.xml

<LinearLayout     
    xmlns:android="http://schemas.android.com/apk/res/android">
    <View 
        android:id="@+id/termometherIndicator"
        android:height="match_parent" android:width="4dp"
        android:background="@color/default_color" />
    <LinearLayout ....>
        <!-- The rest of the item layout goes here -->
    </LinearLayout>
</LinearLayout>

然后使用Id在后​​面的代码中获取视图引用,并将背景颜色更改为您需要的任何颜色。