Tôi có một TableLayout nơi tôi thêm TableRows động. Trong mỗi TableRow, tôi thêm một Button.Thêm khoảng cách giữa các cột trong TableLayout
Tôi chỉ muốn thêm một số khoảng trống giữa các cột (là các nút của tôi) nhưng tôi không thể tìm ra cách ... Tôi đã cố thay đổi tất cả các lề có thể nhưng không hoạt động: ( Vì vậy, có lẽ tôi đã phạm sai lầm trong mã của tôi, nơi tôi thổi phồng chúng từ file XML:
private void createButtons(final CategoryBean parentCategory) {
final List<CategoryBean> categoryList = parentCategory.getCategoryList();
title.setText(parentCategory.getTitle());
// TODO à revoir
int i = 0;
TableRow tr = null;
Set<TableRow> trList = new LinkedHashSet<TableRow>();
for (final CategoryBean category : categoryList) {
TextView button = (TextView) inflater.inflate(R.layout.button_table_row_category, null);
button.setText(category.getTitle());
if (i % 2 == 0) {
tr = (TableRow) inflater.inflate(R.layout.table_row_category, null);
tr.addView(button);
} else {
tr.addView(button);
}
trList.add(tr);
button.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
CategoryBean firstChild = category.getCategoryList() != null && !category.getCategoryList().isEmpty() ? category
.getCategoryList().get(0) : null;
if (firstChild != null && firstChild instanceof QuestionsBean) {
Intent intent = new Intent(CategoryActivity.this, QuestionsActivity.class);
intent.putExtra(MainActivity.CATEGORY, category);
startActivityForResult(intent, VisiteActivity.QUESTION_LIST_RETURN_CODE);
} else {
Intent intent = new Intent(CategoryActivity.this, CategoryActivity.class);
intent.putExtra(MainActivity.CATEGORY, category);
startActivityForResult(intent, VisiteActivity.CATEGORY_RETURN_CODE);
}
}
});
i++;
}
for (TableRow tableRow : trList) {
categoryLaout.addView(tableRow);
}
}
button_table_row_category.xml của tôi:
<?xml version="1.0" encoding="utf-8"?>
<TextView xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/buttonTableRowCategory"
style="@style/ButtonsTableRowCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:text="@string/validate" />
table_row_category.xml của tôi:
<?xml version="1.0" encoding="utf-8"?>
<TableRow xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/tableRowCategory"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_margin="100dp"
android:gravity="center"
android:padding="5dp" >
</TableRow>
Cảm ơn sự giúp đỡ của bạn.
thực sự có nghĩa là bạn muốn thêm khoảng cách giữa các hàng (không phải cột?) – manmal
Bạn có muốn không gian ở giữa nút và tên cột hay không? Không nhận được ý tưởng chính xác .. – Dhruvisha
@manmal Tôi có một cột mới cho mỗi nút. Tôi muốn thêm khoảng cách giữa các cột. Giữa các hàng là ok. – Nico