android developer 网站上的design下载的内容如何处置

党玉涛 发布于 2013/04/15 11:33
阅读 300
收藏 0

可能问题标题描述不清楚,这里细化。android入门,先致谢

在对着书上coding一个能够产生类似彩虹效果的代码,其中利用帧布局,将各个显示深浅不同颜色长短不同的testview重叠,但是代码设置颜色中直接用到(在文末贴出全部代码):

final int[] colors = new int[]

{

    R.color.color1,

    R.color.color2,

    ……}

但是我打开R.java查看里面根本没有定义那些color,但是书上没有写定义,给我感觉它会自动提供。

于是去android developer上看是否有未下载安装的东西,看到design下有icon,colors……这类的东西,但是下载后如何处置这些东西,如何使用啊?还有想请问妥善处理colors后是否就可以直接R.color.color1这样使用?



附下整个代码:

xml布局:

<?xml version = "1.0" encoding = "utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation = "vertical"
    android:layout_width = "fill_parent"
    android:layout_height = "fill_parent"
    >
    <TextView android:id = "@+id/view1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width = "210px"
        android:height = "50px"
        android:background="#ff0000"
        />
   	<TextView android:id = "@+id/view2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width = "180px"
        android:height = "50px"
        android:background="#dd0000"
        
        />
  	 <TextView android:id = "@+id/view3"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width = "150px"
        android:height = "50px"
        android:background="#bb0000"
        />
  	<TextView android:id = "@+id/view4"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width = "120px"
        android:height = "50px"
        android:background="#990000"
        />
  	<TextView android:id = "@+id/view5"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width = "90px"
        android:height = "50px"
        android:background="#770000"
        />
  	<TextView android:id = "@+id/view6"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width = "60px"
        android:height = "50px"
        android:background="#550000"
        />
  	<TextView android:id = "@+id/view7"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:width = "30px"
        android:height = "50px"
        android:background="#330000"
        />
</FrameLayout>
mainactivity.java:

package com.example.rainbow;

import java.util.*;
import android.graphics.Color;
import android.os.*;
import android.app.Activity;
import android.widget.TextView;

public class MainActivity extends Activity {

	private int currentColor = 0;
	final int[] colors = new int[]
			{
				R.color.color7,
				R.color.color6,
				R.color.color5,
				R.color.color4,
				R.color.color3,
				R.color.color2,
				R.color.color1,	
			};
	final int[] names = new int[]
			{
				R.id.view1,
				R.id.view2,
				R.id.view3,
				R.id.view4,
				R.id.view5,
				R.id.view6,
				R.id.view7,
				
			};
	TextView[] views = new TextView[7];
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_main);
		for (int i = 0; i < 7; i++)
			views[i] = (TextView)findViewById(names[i]);
		final Handler handler = new Handler()
		{
			public void handleMessage(Message msg)
			{
				if (msg.what == 0x1122)
					for (int i = 0; i < 7 - currentColor;i++)
						views[i].setBackgroundResource(colors[i+currentColor]);
for (int i = 7 - currentColor, j = 0; i< 7; j++)
						views[i].setBackgroundResource(colors[j]);
			}
		
		};
		 new Timer().schedule(new TimerTask()
		{
			public void run ()
			{
				if(currentColor >= 6)
					currentColor = 0;
				Message m = new Message();
				m.what = 0x1122;
				handler.sendMessage(m);
			}
		},0,100);
		
	}

	
}

加载中
返回顶部
顶部