对不起,我的英语不好。我有一个表格行,我已经用记录的代码设置了第一个视图。我已经将此视图设置为 0px 高度和 0px 宽度。但它需要我半屏!为什么?错误在哪里?
这是代码:
try{
txtId= new TextView(this);
imgCategory= new ImageView(this);
txtDescrizione= new TextView(this);
txtDataFine= new TextView(this);
imgPriorita= new ImageView(this);
txtId.setText(id);
txtId.setWidth(0);
txtId.setHeight(0);
txtId.setTextColor(getResources().getColor(R.color.white));
txtId.setTextSize(1);
if(priorita.equalsIgnoreCase("3")){
imgPriorita.setImageResource(R.drawable.todo_priority_3);}
else if(priorita.equalsIgnoreCase("2")){
imgPriorita.setImageResource(R.drawable.todo_priority_2);}
else if(priorita.equalsIgnoreCase("1")){
imgPriorita.setImageResource(R.drawable.todo_priority_1);}
imgPriorita.setPadding(0, 0, 0, 0);
imgPriorita.setMaxWidth(widthDisplay/10);
imgPriorita.setMaxHeight(40);
imgPriorita.setScaleType(ScaleType.CENTER_INSIDE);
txtDescrizione.setPadding(0, 0, 0, 0);
//txtDescrizione.setText(Html.fromHtml("<i>"+descrizione+"</i>"));
txtDescrizione.setText(descrizione);
txtDescrizione.setTextColor(getResources().getColor(R.color.black));
txtDescrizione.setWidth(widthDisplay/5);
txtDescrizione.setHeight(40);
txtDescrizione.setTextSize(12);
//setto la descrizione su una sola riga e con true fino a quando ci stanno le lettere
txtDescrizione.setSingleLine(true);
txtDescrizione.setLines(1);
txtDataFine.setPadding(0, 0, 0, 0);
txtDataFine.setText(data.getDateTimeTodo(dataFine));
txtDataFine.setWidth(widthDisplay/5);
txtDataFine.setHeight(40);
txtDataFine.setTextColor(getResources().getColor(R.color.black));
txtDataFine.setGravity(Gravity.CENTER);
txtDataFine.setTextSize(12);
if(category.equalsIgnoreCase("2")){
imgCategory.setImageResource(R.drawable.todo_category_2);}
else if(category.equalsIgnoreCase("1")){
imgCategory.setImageResource(R.drawable.todo_category_1);}
else if(category.equalsIgnoreCase("3")){
imgCategory.setImageResource(R.drawable.todo_category_3);}
else if(category.equalsIgnoreCase("5")){
imgCategory.setImageResource(R.drawable.todo_category_5);}
else if(category.equalsIgnoreCase("4")){
imgCategory.setImageResource(R.drawable.todo_category_4);}
else if(category.equalsIgnoreCase("6")){
imgCategory.setImageResource(R.drawable.todo_category_6);}
imgCategory.setPadding(0,0,0,0);
imgCategory.setMaxWidth(widthDisplay/5);
imgCategory.setMaxHeight(40);
imgCategory.setScaleType(ScaleType.CENTER_INSIDE);
rowTodo[counterBackground]= new TableRow(this);
if((counterBackground%2)==0){
rowTodo[counterBackground].setBackgroundColor(getResources().getColor(R.color.greyListCp));}
else{
rowTodo[counterBackground].setBackgroundColor(getResources().getColor(R.color.white));}
rowTodo[counterBackground].setMinimumHeight(heightRowTodo);
idRow_gl=Integer.parseInt(id);
rowTodo[counterBackground].setId(idRow_gl);
rowTodo[counterBackground].setOnClickListener(new OnClickListener() {
public void onClick(View view_cliccata) {
onclickRow(view_cliccata);
}
});
imgAnagraficaTodo[counterBackground]=new ImageView(this);
if(id_anagTodo.equals("")){}
else{
imgAnagraficaTodo[counterBackground].setImageResource(R.drawable.toanag);
imgAnagraficaTodo[counterBackground].setPadding(20, 3, 0, 0);
imgAnagraficaTodo[counterBackground].setMinimumWidth(widthDisplay/5);
imgAnagraficaTodo[counterBackground].setMaxHeight(40);
imgAnagraficaTodo[counterBackground].setId(idRow_gl);
imgAnagraficaTodo[counterBackground].setScaleType(ScaleType.CENTER_INSIDE);
imgAnagraficaTodo[counterBackground].setOnClickListener(new OnClickListener() {
public void onClick(View view_cliccata) {
Data.myHashMapVar.put("ID_TODO", view_cliccata.getId());
onclickImgAnagraficaTodo(view_cliccata,id_anagTodo);
}
});
arrList_AnagTodo.add(id_anagTodo);
}
rowTodo[counterBackground].addView(txtId);
rowTodo[counterBackground].addView(imgPriorita);
rowTodo[counterBackground].addView(txtDescrizione);
rowTodo[counterBackground].addView(txtDataFine);
rowTodo[counterBackground].addView(imgCategory);
rowTodo[counterBackground].addView(imgAnagraficaTodo[counterBackground]);
List_TodoList.addView(rowTodo[counterBackground]);
} catch (Exception e) {
e.printStackTrace();
}
}
而heightDisplay和widthDisplay是这样设置的:
display=getWindowManager().getDefaultDisplay();
heightDisplay=display.getHeight();
widthDisplay=display.getWidth();
提前致谢!