2013-07-19 1 views
0

버튼을 10x10 보드로 만들지 만, 프로그램을 실행할 때마다 더 이상 볼 수 없을 때까지 버튼이 아래쪽으로 확장되어 있습니다. 여기에 내 코드입니다 :TableLayout 문제

@Override 
protected void onCreate(Bundle icicle) { 
    super.onCreate(icicle); 
    setContentView(R.layout.game); 
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(32, 32); 
    final TableLayout container = (TableLayout) findViewById(R.id.tableLayout5); 

    Button btn[][] = new Button[10][10]; 

    for(int i = 0; i<10; i++){ 
     for(int j = 0; j<10; j++){ 
      btn [i][j] = new Button(this); 


      container.addView(btn[i][j],i,lp); 

     } 

    } 

} 

내 XML 코드

<RelativeLayout 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:id="@+id/relativeLayout5"> 



    <Button 
    android:id="@+id/newgamebutton" 
    android:layout_width="225dp" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:text="@string/newgame" /> 

    <TableLayout 
     android:id="@+id/tableLayout5" 
     android:layout_width="fill_parent" 
     android:layout_height="400dp" 
     android:layout_alignParentLeft="true" 
     android:layout_below="@+id/newgamebutton" 
     android:orientation="vertical" > 

    </TableLayout> 

</RelativeLayout> 

나는 버튼이 하단에있는 모든 방법을 확장하는 이유를 궁금해하고있는 뭔가가 있다면, 나도 몰라 사라지는거야 내 레이아웃 높이로할지 어떨지. 나는 10x10 보드처럼 보이게하려고합니다.

+0

시도는 왜 안 그리드를 사용하십시오있는 ScrollView – Raghunandan

+0

내부 TableLayout을 넣어? – Giant

답변

0

10x10 보드의 보드가 필요한 경우 TableRows를 만들어야합니다. 현재 아무 것도 없습니다. 어떻게 작동하는지 이해하려면 TableLayout 설명서를 읽으십시오.

두 번째로 테이블의 레이아웃 매개 변수를 프로그래밍 방식으로 설정해야하는 경우 ViewGroup.LayoutParams가 아니라 TableRow.LayoutParams를 사용해야합니다.

ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(32, 32); 

나는이 대신 사용 :

TableRow.LayoutParams lp = new TableRow.LayoutParams(32, 32);