标签:android style blog http java color 使用 os
public class Pane {
private int locationX;
private int locationY;
private PaneState state = PaneState.INVISIBLE;
private String visitor;
public Pane(){}
public Pane(int locationX,int locationY,PaneState state,String visitor){
this.locationX = locationX;
this.locationY = locationY;
this.state = state;
this.visitor = visitor;
}
...
public void setView(View view){
view.setClickable(true);
switch (state) {
case VISIBLE:
view.setVisibility(View.VISIBLE);
view.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.setVisibility(View.INVISIBLE);
}
});
break;
case INVISIBLE:
view.setVisibility(View.INVISIBLE);
break;
case PORTRAIT:
break;
default:
break;
}
}
}public enum PaneState {
VISIBLE(0) , INVISIBLE(1) , PORTRAIT(2);
...
} private void init(){
this.removeAllViews();
for(int y=0; y<rowNum; ++y){
TableRow row = new TableRow(context);
row.setLayoutParams(new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT, 1.0f));
for(int x=0; x<colNum; ++x){
items.add(new View(context));
View button = items.get(y*rowNum + x);
button.setBackgroundColor(Color.BLUE);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
v.setVisibility(View.INVISIBLE);
}
});
row.addView(button, new TableRow.LayoutParams (LayoutParams.MATCH_PARENT, LayoutParams.MATCH_PARENT, 1.0f));
}
this.addView(row);
}
}
public void setDataAndDraw(int rowNum,int colNum,List<Pane> paneList){
this.rowNum = rowNum;
this.colNum = colNum;
setDataAndDraw(paneList);
}
public void setDataAndDraw(List<Pane> paneList){
init();
Iterator<Pane> iterator = paneList.iterator();
while(iterator.hasNext()){
Pane pane = iterator.next();
int index = pane.getLocationY() * rowNum + pane.getLocationX();
pane.setView(items.get(index));
}
}List<Pane> list = new ArrayList<Pane>(); Pane pane1 = new Pane(0,0,PaneState.valueOf(1),null); Pane pane2 = new Pane(1,1,PaneState.valueOf(1),null); Pane pane3 = new Pane(2,2,PaneState.valueOf(1),null); list.add(pane1); list.add(pane2); list.add(pane3); gridView.setDataAndDraw(list);
{"PaneList":[{"locationX":0,"locationY":0,"PaneState":1,"visitor":""},{"locationX":0,"locationY":0,"PaneState":1,"visitor":""},{"locationX":0,"locationY":0,"PaneState":1,"visitor":""}]}标签:android style blog http java color 使用 os
原文地址:http://blog.csdn.net/toyuexinshangwan/article/details/38140083