Tôi muốn tự động tạo các nút theo chiều dọc với lề dưới 20px giữa các nút. Tôi cố gắng thiết lập lề với một đối tượng LayoutParams, mà không thành công.android: đặt lề giữa các nút bằng LayoutParams
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/regions_search"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginBottom="30dip"
android:orientation="vertical" >
</LinearLayout>
@Override
public void onCreate(Bundle savedInstanceState) {
...
for (Region region : regionsList) {
//create new button
Button button = new Button(mContext);
//set infos
int id = Integer.parseInt(Long.toString((Long) region.getId())); button.setId(id);
button.setText(region.getName() + "(" + region.getStores_nb() + ")");
//Layoutparams setting
FrameLayout.LayoutParams params = new FrameLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
params.setMargins(0, 0, 0, 20);
button.setLayoutParams(params);
myLinear.addView(button);
}
Như bạn có thể thấy trên hình ảnh, không có khoảng cách giữa các hình ảnh. Ai đó biết tại sao? Cảm ơn bạn!
Tại sao bạn sử dụng FrameLayout? Tệp XML nằm trong LinearLayout. –
Xong, cảm ơn bạn – johann