2013-11-22 2 views
0

화면의 70 %를 차지하는 버튼이있는 5x5 테이블을 만들려고합니다. 이 아래에 스크롤 막대 (화면의 맨 아래 의미하는)와 함께 단추를 가로로 놓고 싶습니다. java 및 xml 파일은 다음과 같습니다. 출력 화면에서 5x5 테이블 만 생성 된 것을 볼 수 있으며 하단 공간은 공백으로 남습니다. 나는 안드로이드와 레이아웃에 익숙하지 않으므로 이것으로 나를 도와주세요. 감사!화면 하단에 가로 스크롤보기가있는 선형 레이아웃 만들기

XML 파일 :

<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical"> 

<TableLayout 
    android:id="@+id/mainPage" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">   
</TableLayout> 

<HorizontalScrollView 
    android:id="@+id/hsvMain" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content">   

    <LinearLayout 
     android:id="@+id/scroll_ll" 
     android:layout_width="wrap_content" 
     android:layout_height="fill_parent" 
     android:isScrollContainer="true" 
     android:scrollbars="horizontal" 
     android:orientation="horizontal"> 
     </LinearLayout>  
    </HorizontalScrollView> 


</LinearLayout> 

자바 파일 :

protected void onCreate(Bundle savedInstanceState) 
{ 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.match_main_skl); 
    table = new TableLayout (this); 
    setControls(); 

    hsv = new HorizontalScrollView(this); 
    ll = new LinearLayout(this); 
    mainTable(); 
} 

private void setControls() 
{ 
    table = (TableLayout) findViewById(R.id.mainPage); 
    hsv = (HorizontalScrollView) findViewById(R.id.hsvMain); 
    ll = (LinearLayout) findViewById(R.id.scroll_ll); 

} 

private void mainTable() 
{ 
    //find screen size of the device (supports all versions) 
    Point windowSize = MAUIUtil.GetDefaultWindowSize(this); 
    int cellSize; 
    if (windowSize.x >= 0.70 * windowSize.y) 
     cellSize = windowSize.x/numColumns; 
     else cellSize = (int) ((0.70*windowSize.y)/numColumns); 


**//5x5 TABLE** 
    TableRow.LayoutParams buttonRow = new TableRow.LayoutParams(TableRow.LayoutParams.MATCH_PARENT, TableRow.LayoutParams.MATCH_PARENT, 1.0f); 
    buttonRow.height = cellSize * numRows; 
    //buttonRow.height = windowSize.x; 
    table.setLayoutParams(buttonRow); 
    table.setStretchAllColumns(true); 


    for(int rw = 0; rw < numRows; rw++) 
    { 
     TableRow row = new TableRow(this); 

     row.setPadding(0, 0, 0, 0); //setPadding(left,top,right,bottom) 
     row.setId(ROW_ID_OFFSET + rw);//giving each row an id 

     TableLayout.LayoutParams tbLp = new TableLayout.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT,1.0f); 
     tbLp.height = cellSize; 
     table.setLayoutParams(tbLp); 

     for(int col = 0; col < numColumns; col++) 
     { 
      int btnID = COLUMN_ID_OFFSET + (numColumns * (rw - 1)) + col; 

      //Adding buttons 
      Button btn = new Button(this); 
      btn.setId(btnID); 
      btn.setPadding(0, 0, 0, 0); 
      btn.setTypeface(Typeface.DEFAULT_BOLD); 
      btn.setBackgroundColor(Color.CYAN); 
      btn.setText(Integer.toString(btnID)); 

      row.addView(btn); 
     } 
     table.addView(row); 
    } 

    **//LAST SCROLLABLE HORIZONTAL ROW** 

    hsv.addView(ll); 

    LinearLayout.LayoutParams llp = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT, 1.0f); 
    llp.height = windowSize.y - cellSize; 
    hsv.setLayoutParams(llp); 

    LinearLayout sll = new LinearLayout(this); 

    for(int col = 0; col < scrNumColumns; col++) 
    { 
     int btnID = SCROLL_COLUMN_ID_OFFSET + col; 

     //Adding buttons 
     Button btn = new Button(this); 
     btn.setId(btnID); 
     btn.setPadding(0, 0, 0, 0); 
     btn.setTypeface(Typeface.DEFAULT_BOLD); 
     btn.setBackgroundColor(Color.RED); 
     btn.setText(Integer.toString(btnID)); 

     sll.addView(btn); 
     sll.setGravity(Gravity.BOTTOM); 
    } 
    ll.addView(sll); 
} 
+0

tableLayout에 Layout_weight를 .7로, linearLayout에 .3 – Manishika

답변

0

당신이에서 onCreate() 메소드에서 findViewById를()를 호출 한 후 새의 LinearLayout 새로운 HorizontalScrollView를 만든 것 같다. 따라서 .xml 파일에 정의 된보기보다는 새로 만든보기를 조작하고 있습니다.

다음 행을 삭제하십시오 : 당신이 설명대로 code.I 아래

hsv = new HorizontalScrollView(this); 
ll = new LinearLayout(this); 
+0

을 사용하십시오. 선형 레이아웃에서 android : alain_parentBottom = "true"를 사용하면 원하는 것을 얻을 수 있습니다. – Dev

0

를 사용하여 그것을 구현했습니다.

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:id="@+id/LinearLayout1" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 


> 

<TableLayout 
android:layout_width="fill_parent" 
android:layout_height="wrap_content" 
> 

    <TableRow > </TableRow> 
    <TableRow > </TableRow> 
    <TableRow > </TableRow> 
    <TableRow > </TableRow> 
    <TableRow > </TableRow> 


</TableLayout> 

<HorizontalScrollView 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" > 

<LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:orientation="horizontal"> 

<Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button1"/> 
    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button2"/> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button3"/> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button4"/> 

    <Button 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:text="Button5"/> 


     </LinearLayout> 

</HorizontalScrollView> 



</RelativeLayout> 

희망 하시겠습니까? 추가 질문이 있으시면 문의 해주십시오.

0

android:alain_parentBottom="true"을 선형 레이아웃으로 사용하면 원하는 것을 얻을 수 있습니다.

관련 문제