버튼 사이에 20px의 하단 여백을 사용하여 수직으로 버튼을 자동 생성하려고합니다. 나는 성공없이 LayoutParams 객체로 여백을 설정하려고합니다.android : 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);
}
이미지에서 볼 수 있듯이 이미지 사이에는 공백이 없습니다. 왜 그 사람이 누군지 알아? 감사합니다.
가 왜 FrameLayout이 사용합니까? XML 파일은 LinearLayout에 있습니다. –
완료, 고맙습니다. – johann