自定義的TextView實現一個帶漸變效果的ListView
Use a user-defined TextView(MaskTextView) to achieve a ListView with gradient effect.
用一個自定義的TextView(MaskTextView)去實現一個帶漸變效果的ListView
Introduce
Actually,this GradientListView is made by a user-defined TextView with MaskEffect,Through the text set to transparent and set the gradient background resource,then you get it. The text color is the background's color
實際上,這個漸變效果的ListView是用一個有蒙板效果的自定義TextView做的,通過把文字設置成透明,再設置一個漸變效果的背景資源,就完成了。文字的顏色就被是背景資源的顏色。
Attentions
1、The Class ‘MaskTextView’ (A user-defined TextView).
lineNumber 56:c.drawColor(Color.argb(255, 50, 50, 50));
You can change the color you need,ensure the Alpha value is 255 so the text's surrounding is not transparent.
(譯:類MyTextView是自定義的TextView; 56行:c.drawColor(Color.argb(255, 50, 50, 50)); 您可以根據自己的需要進行調節顏色,但是Alpha值應該為255保證其不透明)
2、The Class ‘MaskTextView’
lineNumber 57:c.drawText(getText().toString(), 50, 80, mTextPaint);
You can change the text's position by need.
(譯:類MyTextView 57行c.drawText(getText().toString(),50,80, mTextPaint); 調節文字的位置,根據需要自行調節)
3、In the item's xml_layout,Replace the TextView to MaskTextView;
(譯:在ListView的條目布局中,把TextView替換為MaskTextView)
4、Set the background resources for the gradient background you want,You can display background with a FrameLayout.
(譯:設置背景資源為你想要的漸變背景,可以用一個幀布局來顯示背景)
<FrameLayout android:layout_width="match_parent" android:layout_height="match_parent" android:background="@drawable/bg4" > </FrameLayout> <ListView android:id="@+id/lv_gradient" android:layout_width="wrap_content" android:layout_height="wrap_content" android:divider="@null" />