나는 GridLayout
을 가지고 있고 두 개 이상의 버튼이 안에 있으며 모든 버튼은 같은 너비를 가져야합니다. 내 문제는 다른 줄 번호의 단추가있을 때 단추의 marginTop
도 다를 것입니다. 이 문제를 어떻게 해결할 수 있습니까? 나는 모든 버튼을 같은 높이의 위치에두기를 원한다.버튼 layout_gravity = "fill_vertical"을 프로그래밍 방식으로 설정하는 방법은 무엇입니까?
감사합니다.
이미 Gravity
을 FILL_VERTICAL
으로 설정하려고했지만 작동하지 않습니다.
이 지금 너무 노력하고 있습니다 : 여기
GridLayout grid_neighbor = (GridLayout) findViewById(R.id.grid_neighbors);
grid_neighbor.setColumnCount(4);
for (i = 0; i < namelist.length; ++i) {
Button temp = new Button(this);
temp.setText(namelist[i]);
LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.gravity = Gravity.FILL_VERTICAL;
temp.setLayoutParams(lp);
//temp.setGravity(Gravity.FILL_VERTICAL);
temp.setWidth(button_size);
temp.setHeight(button_size);
grid_neighbor.addView(temp);
}
는 사진입니다.
GridLayout grid_neighbor = (GridLayout) findViewById(R.id.grid_neighbors);
grid_neighbor.setColumnCount(4);
for (i = 0; i < namelist.length; ++i) {
Button temp = new Button(this);
temp.setText(namelist[i]);
RelativeLayout.LayoutParams lp = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);
lp.addRule(RelativeLayout.ALIGN_TOP, temp.getId());
temp.setLayoutParams(lp);
//temp.setGravity(Gravity.FILL_VERTICAL);
temp.setWidth(button_size);
temp.setHeight(button_size);
grid_neighbor.addView(temp);
}
감사.
GridLayout.Spec speccolumn = GridLayout.spec(i%4);
GridLayout.Spec specrow = GridLayout.spec(i/4, GridLayout.TOP);
grid_neighbor.addView(temp, new GridLayout.LayoutParams(specrow, speccolumn));
추가 규칙 첫 번째 버튼으로 상단 맞춤 – OMAK
채우기 부모가 상위의 높이를 갖도록 버튼을 설정할 수 없습니까? – Hardik4560
@OMAK addRule (RelativeLayout.ALIGN_TOP) 및 ALIGN_PARENT_TOP 모두 작동하지 않습니다. – JamesChiang