TableLayout relativeLayout = (TableLayout)findViewById(R.id.ll1);
TableRow row =new TableRow(this);
Button button ;
int counter = 0;
for(int i = 0;i<=13;i++){
counter++;
button = new Button(this);
button.setText(counter);
row.addView(button);
}
relativeLayout.addView(row,new TableLayout.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));
relativeLayout.computeScroll();
XML 파일레이아웃 및 버튼
<TableLayout android:id="@+id/ll1" android:shrinkColumns="true"
android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_below="@id/button1"
xmlns:android="http://schemas.android.com/apk/res/android"></TableLayout>
하지만 난 내 응용 프로그램을 실행할 때마다이 하나의 행 내 버튼을 이동하고 5 개 버튼 후 모든 버튼이 화면 밖으로 이동합니다. 나는 더 많은 행을 추가하고 싶지 않다. 왜냐하면 (카운터 % 5 == 0) 어떤 코드를 배치하는 것과 같이 내 코드에서 하드 코딩을하고 싶지 않기 때문이다.
단추가 화면 너비와 같은 경우 너비를 계산할 수있는 다른 방법이 있습니까? 아니면 행의 내용을 단순히 감싸는 테이블 레이아웃의 속성과 같은 방법으로 할 수 있습니까?
행이 하나 뿐인 경우 LinearLayout을 사용하십시오! 나는 네가하고 싶은 것을 실제로 이해하지 못한다. 레이아웃에 버튼을 추가 할 때 어떻게해야합니까? 화면에 어떻게 표시해야합니까? 한 줄, 여러 줄 ??? – nenito