2013-07-19 2 views
1

내가 만든 버튼 배열의 버튼 크기를 조정하려고하지만,어떻게 버튼 배열에 버튼 크기를 조정하려면

@Override 
protected void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.game); 
    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); 

     } 

    } 

} 
+1

당신은 버튼 크기를 조정하여 무엇을 의미합니까? 설정 한 후에 크기를 설정하거나 크기를 변경하는 것을 의미합니다. – Azad

답변

0

모르겠어요

여기 내 코드의 방법을 모르겠어요 당신이 알고있는 경우에, 그러나 이것은 어쨌든, 100 개 버튼을 만들 것입니다 : 당신은 내가 여기에 다른 사양을 참조하지 않기 때문에 내가 가정하고있어 java.awt.Button 클래스를 사용하는 경우는이

public void onCreate(Bundle icicle) 
{ 
    super.onCreate(icicle); 
    ViewGroup.LayoutParams lp = new ViewGroup.LayoutParams(width_of_button , height_of_button); 
    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); 
      btn.setText("Button "+i+":"+j); // if you need to trace which is which 



      container.addView(btn[i][j],i,lp);// add button with specified dims 

    } 
0

같이 수행 할 수 있습니다 y를 크기를 지정하려면 java.awt.Dimension 개체를 만들어야합니다.

Dimension size=new Dimension(4,6); //where 4 is the width and 6 is the height, although odds are you will need something much bigger 

for(int i = 0; i<10; i++) 
{ 
    for(int j = 0; j<10; j++) 
    {  
     btn [i][j] = new Button(this); 
     btn.setSize(size); //inherited from Component 

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

높이와 너비를 적절하게 변경하면 효과가 있습니다. 당신은 또한 다음과 같이 수정 그것의 LayoutParams에 의해 java.awt.Dimension의에게

+1

코드는 자바이지만, 그는 안드로이드를 사용하고 있습니다. thinlk에는 java.awt.Button이 있습니다. – FutureSci

0

당신은 크기를 조정할 수 있습니다 버튼을 가져와야합니다 :

TableLayout.LayoutParams params = new TableLayout.LayoutParams(); 
    params.height = 40; 
    params.width = 100; 
    button.setLayoutParams(params); 
관련 문제