Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/360.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 如何在每个ListView行上显示左边框?_Java_Android_Listview_Colors_Border - Fatal编程技术网

Java 如何在每个ListView行上显示左边框?

Java 如何在每个ListView行上显示左边框?,java,android,listview,colors,border,Java,Android,Listview,Colors,Border,如何在每个ListView行上仅显示左边框 我有一个5度的用户声誉术语表,我想在每个listview行的左边框显示相应的颜色 像这样 谢谢大家 您可以在应用程序最左侧添加一个面板。在该面板中,可以放置温度计的一个预定义图像。你只有5级,对吗?一旦值发生变化-选择温度计读数的相应图像并重新绘制gui元素。列表视图行应为水平线性布局,并将其作为第一个子项包含在开头,然后是文本视图: <View android:id="@+id/reputationColor" android:layout_w

如何在每个ListView行上仅显示左边框

我有一个5度的用户声誉术语表,我想在每个listview行的左边框显示相应的颜色

像这样


谢谢大家

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

列表视图行应为水平
线性布局
,并将其作为第一个子项包含在开头,然后是文本视图:

<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"
/>
有关CustomAdapters的更多信息,请访问以下网站:


最简单的方法是在项目布局中创建一个虚拟的
视图。这样,当您将布局绑定到数据时,可以轻松地更改背景颜色。大概是这样的:

项目列表布局.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
获取代码隐藏中的视图参考,并将背景颜色更改为您需要的颜色。

请澄清您的具体问题或添加其他详细信息,以突出显示您需要的内容。正如目前所写的,很难准确地说出你在问什么。请参阅页面以获取澄清此问题的帮助。如下图所示
<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>