一. 實現很簡單,就是對顏色進行線性的漸變。用到的類是LinearGradient.直接貼代碼:
public class Test extends Activity {
private TextViewTest mTextViewTest;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mTextViewTest = new TextViewTest(this);
setContentView(mTextViewTest);
}
public class TextViewTest extends TextView {
private LinearGradient mGradient;
private int[] mGradientColors = { Color.RED, Color.rgb(255, 165, 0),
Color.YELLOW, Color.GREEN, Color.rgb(0, 255, 255), Color.BLUE,
Color.rgb(160, 32, 240) };
private int mTitleWidth;
private String mTitle = "三十六天罡,七十二地煞,乃是天地正邪之氣所生,如今奉命下凡轉世為科學家.但法用以正,則可以造福人群;";
public TextViewTest(Context context) {
super(context);
// TODO Auto-generated constructor stub
setLayoutParams(new LinearLayout.LayoutParams(
LinearLayout.LayoutParam