如何僅在每個ListView行上顯示左邊的彩色邊框?如何在每個ListView行上顯示左邊的彩色邊框?
我有一個用戶信譽5度termometer,我想在每個listview行的左邊界顯示各自的顏色。
像這樣link
謝謝你們!
如何僅在每個ListView行上顯示左邊的彩色邊框?如何在每個ListView行上顯示左邊的彩色邊框?
我有一個用戶信譽5度termometer,我想在每個listview行的左邊界顯示各自的顏色。
像這樣link
謝謝你們!
最簡單的方法是在你的項目佈局,以創建一個虛擬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
代碼視圖參考,並切換到任何你所需要的背景顏色。
您可以將面板添加到應用的最左側部分。在該面板中,您可以放置溫度計的預定義圖像之一。你只有5個關卡,對吧?一旦數值發生變化 - 選擇相應的溫度計讀數圖像並重新繪製gui元素。
的ListView
行應該是一個水平LinearLayout
,以及包括此之初,作爲第一個孩子,接着TextView的:
<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
爲您ListView
,你可以找到在here
的CustomAdapter裏面一個完整的例子,你可以用
View reputationColor = (View)findViewById(R.id.reputationColor);
switch (reputation) {
case 1:
reputationColor.setBackgroundColor(#ff0000);
break; //Include other cases up to 5
default:
break;
}
編程設置顏色3210
有關CustomAdapters更多信息,請訪問以下網站:
請說明您的具體問題或添加額外的細節,以確切地突出你需要什麼。正如目前所寫,很難確切地說出你在問什麼。請參閱[Ask]頁面以獲得澄清此問題的幫助。 –
想要這樣[link](http://imgur.com/a/Z2u76) – marcelofb