一般Table的数据(行)更新时,要配合一定的动画效果,才能引起用户注意。
在Android里,颜色值用8位的16进制来表示,其中前两2位用来表示 alpha channel, 后6位用来表示rgb. 在程序里面,只要在指定时间内,将alpha channel从 0调整到 0xff,就实现了 highlight TableRow.
class ColorRefreshTask extends TimerTask {
final static int DELAY_ONCE =200;
final static int TOTAL_RUNTIME = 3000;
final static int POWER_16_16 = 16 * 16* 16 * 16 * 16 * 16;
final static int INCREASE_ONCE = 0xff / (TOTAL_RUNTIME / DELAY_ONCE);
int color;
int id;
int startTime;
int alphaChannel;
/**
*
* @param color (TableRow's current background color)
* @param id TableRow's id(user id)
*/
public ColorRefreshTask(int color, int id) {
super();
Log.d("color", "ready to set color!");
this.color = color;
this.id = id;
this.startTime = 0;
this.alphaChannel = 0;
}
public void run(){
int colorComm = color -0xff000000; //RGB color value;
int currColor = color;
if(startTime < TOTAL_RUNTIME) {
startTime += DELAY_ONCE;
alphaChannel += INCREASE_ONCE;
currColor = POWER_16_16 * alphaChannel + colorComm;
Log.d("color", Integer.toHexString(currColor));
sendMsg(currColor);
messageHandler.postDelayed(this,DELAY_ONCE);
}
else {
sendMsg(currColor);
}
}
public void startTimer(){
messageHandler.postDelayed(this,DELAY_ONCE);
}
private void sendMsg(int currColor){
Message message = messageHandler.obtainMessage();
message.what = MESSAGE_HANDLE_ID_UPDATEROW_BACKGROUND;
Bundle bundle = new Bundle();
bundle.putInt(MESSAGE_KEY_ID, id);
bundle.putInt(MESSAGE_KEY_COLOR, currColor);
message.setData(bundle);
messageHandler.sendMessage(message);
}
public void stopTimer(){
this.cancel();
}
}
private static final int MESSAGE_HANDLE_ID = 800;
private static final int MESSAGE_HANDLE_ID_UPDATEROW_DATA = MESSAGE_HANDLE_ID + 1;
private static final int MESSAGE_HANDLE_ID_UPDATEROW_BACKGROUND = MESSAGE_HANDLE_ID +2;
private Handler messageHandler = new Handler() {
@Override
public void handleMessage(Message msg) {
switch(msg.what) {
case MESSAGE_HANDLE_ID_UPDATEROW_DATA:{
int id = msg.getData().getInt(MESSAGE_KEY_ID);
String fields[] = new String[5];
fields[0] = msg.getData().getString("fields1");
fields[1] = msg.getData().getString("fields2");
fields[2] = msg.getData().getString("fields3");
fields[3] = msg.getData().getString("fields4");
fields[4] = msg.getData().getString("fields5");
updateRowInTable(id, fields);
break;
}
case MESSAGE_HANDLE_ID_UPDATEROW_BACKGROUND:
{
int id = msg.getData().getInt(MESSAGE_KEY_ID);
int color = msg.getData().getInt(MESSAGE_KEY_COLOR);
TableRow tableRow= (TableRow)findViewById( id);
if(tableRow != null) {
int count = tableRow.getChildCount();
for(int index = 0; index < count; index++) {
TextView child = (TextView)(tableRow.getChildAt(index));
if(child != null) {
child.setBackgroundColor(color);
}
}
}
break;
}
default:
}
}
};
private final void updateRowInTable(int code,String[] otherFields) {
TableRow tableRow= (TableRow)findViewById(code);
if(tableRow == null) {
Log.d("tablerow", "can't find row in the table!");
return;
}
int bgColorEnd = (otherFields[2].indexOf("-") >= 0) ? 0xff2e8b57 : 0xffb22222;
for(int index = 0; index < otherFields.length; index++) {
int identity = code * 13 +(index+1);
TextView textView= (findViewById(identity)!= null) ? (TextView) findViewById(identity) : new TextView(this);
if(otherFields[index].indexOf('-') >=0) {
textView.setTextColor(Color.GREEN);
}
else if( index == 2) {
textView.setTextColor(Color.RED);
}
else {
textView.setTextColor(Color.WHITE);
}
textView.setText(otherFields[index]);
Log.d("tablerow", "updated id:" + (code) + ", value=" + otherFields[index] );
if(findViewById(identity) == null){
textView.setId(identity);
tableRow.addView(textView);
Log.d("tablerow", "add new view!");
}
else {
Log.d("tablerow", "upate view!");
}
textView.postInvalidate();
//textView.invalidate();
}
tableRow.postInvalidate();
//tableRow.invalidate();
ColorRefreshTask refresh = new ColorRefreshTask(bgColorEnd,code);
messageHandler.postDelayed(refresh, 50);
}
分享到:
相关推荐
Table TableRow TableCell与Bom模型 与事件处理机制 与js 面向对象的基础;
但是我使用后并没有出现预初想要第一行高亮的效果,然后console.log(row, rowIndex),发现控制台输出的值均为undefined。最终解决方案是只要传入row或者rowIndex即可,然后根据自己所要的数据而进行处理,后来我修改...
Android应用源码开发Demo,主要用于毕业设计学习。
点按钮添加TableRow源码.zip
Android点按钮添加TableRow源码.zip
Android 点按钮添加TableRow源码.rar
Android 点按钮添加TableRow源码.zip
安卓Android源码——点按钮添加TableRow源码.zip
table row的使用在Androidy studio中有着很重要的作用,对于初学者来说,有一个列子能够更好的学习,本代码就是如此,希望能对需要帮助的有一点帮助吧!!table row是Android studio表格使用,本资源中还有对Spinner...
添加鼠标滑动效果,使得当鼠标移上移开某个单元格时,此行此列高亮显示。
tableRow 表格与复选框配合jquery插件.zip
Android程序研发源码Android 点按钮添加TableRow源码
table 绑定数据 jquery 分页 table 绑定数据 jquery 分页 table 绑定数据 jquery 分页
Android 点按钮添加TableRow源码.zip项目安卓应用源码下载Android 点按钮添加TableRow源码.zip项目安卓应用源码下载 1.适合学生毕业设计研究参考 2.适合个人学习研究参考 3.适合公司开发项目技术参考
界面布局之表格布局TableLayout+TableRow(代码).
最简单的方法就是: //当前页的刷新 $(".layui-laypage-btn")[0].click();...以上这篇layui前端框架之table表数据的刷新方法就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持软件开发网。