【发布时间】:2011-07-10 18:26:54
【问题描述】:
首先,我是 android 开发的新手,一些看似简单的任务让我很沮丧。这是对此处回答的问题的后续问题:Changing the checkbox size in Android 2.0
它的要点是,由于某种原因,我的复选框旁边一直出现这个额外的空间(见下文)。
现在我尝试将宽度设置为 1,但它并没有比显示的更短。我尝试将宽度设置得更大,我可以使尺寸更大,但不能更短。
请看看下面的代码,让我知道你看到了什么。
TableLayout table = (TableLayout) findViewById(R.id.timeEntriesTable);
for (int i = 0; i < timeEntries.getLength(); i++)
{
Element element = (Element) timeEntries.item(i);
TableRow tr = new TableRow(this);
tr.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
CheckBox box = new CheckBox(this);
box.setButtonDrawable(getResources().getDrawable(R.drawable.checkbox_off_background));
box.setPadding(0,0,0,0);
box.setWidth(1);
box.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
CheckBox box = (CheckBox) v;
if (box.isChecked())
{
box.setButtonDrawable(getResources().getDrawable(R.drawable.checkbox_on_background));
}
else
{
box.setButtonDrawable(getResources().getDrawable(R.drawable.checkbox_off_background));
}
}
});
TextView dateBox = new TextView(this);
String dateText = element.getAttribute("date");
dateBox.setText(dateText);
dateBox.setTextColor(Color.BLACK);
TextView customerBox = new TextView(this);
String customerName = element.getAttribute("customer");
customerBox.setText(customerName);
customerBox.setTextColor(Color.BLACK);
TextView hoursBox = new TextView(this);
String hours = element.getAttribute("hours");
hoursBox.setText(hours);
hoursBox.setTextColor(Color.BLACK);
TextView test = new TextView(this);
test.setTextColor(Color.RED);
test.setText("Test");
tr.addView(box);
tr.addView(dateBox);
tr.addView(customerBox);
tr.addView(hoursBox);
table.addView(tr, new LayoutParams(LayoutParams.MATCH_PARENT, LayoutParams.WRAP_CONTENT));
}
提前谢谢你!
【问题讨论】:
标签: android checkbox android-widget padding margin