作者noodleT (面T)
看板AndroidDev
标题[问题] gridView 不同背景色
时间Tue Mar 11 13:44:53 2014
想在萤幕上做n*n的网格,每个网格会有不同的颜色(黑色或白色)
并且要能随时间由黑变白或由白变黑。
我的做法是:
在 drawable 放入黑、白两张图,
在 GridView 上产生n*n个 ImageView
再读入所对应的图。执行果相当耗时间,
不知道能不能直接在n*n的 GridView 中直接着色?不要使用 ImageView
--
我是面T,哩贺
http://ppt.cc/-eS5
--
※ 发信站: 批踢踢实业坊(ptt.cc)
◆ From: 1.172.56.21
1F:推 zxc190:adapter的getItem中设定背景颜色 03/12 15:49
2F:推 chiel:adapter的getView()里面 convertView.setBackgroundColor 03/13 00:19
3F:→ chiel:(Color.BLACK or Color.WHITE); 03/13 00:20
昨天我尝试:
TextView[] pixel = new TextView[900];
GridLayout gridLayout = (GridLayout) findViewById(R.id.gridLayout);
for(int i = 0;i<900;i++){
pixel[i] = new TextView(this);
gridLayout.addView(pixel[i]);
pixel[i].setBackgroundColor(Color.YELLOW);
}
但这样子载入速度也是很慢。
会造成速度慢的原因是上面的程式码产生过多的 View 吗?
使用 getItem 的方法可以避免产生一堆 View?
谢谢
※ 编辑: noodleT 来自: 61.227.97.248 (03/13 11:29)
5F:→ tails32100:在Adapter#getView()里 去设View的background 03/13 14:07