2014-09-02 7 views
1

내가하려는 것은 TableLayout에서 모든 패딩 및 여백을 제거하고 바둑판 식으로 배열 된 자식 버튼을 표시하는 것입니다. Android TableLayout 패딩 제거

이 내가 무엇을 얻을

<TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    xmlns:tools="http://schemas.android.com/tools" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:paddingLeft="@dimen/activity_horizontal_margin" 
    android:paddingRight="@dimen/activity_horizontal_margin" 
    android:paddingTop="@dimen/activity_vertical_margin" 
    android:paddingBottom="@dimen/activity_vertical_margin" 
    tools:context=".Main" 
    android:orientation="horizontal" 
    android:baselineAligned="false"> 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button" 
      android:id="@+id/button1" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button" 
      android:id="@+id/button4" /> 
    </TableRow> 

    <TableRow 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content"> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button" 
      android:id="@+id/button2" /> 

     <Button 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="New Button" 
      android:id="@+id/button3" /> 
    </TableRow> 

</TableLayout> 

모든 패딩은 0

로 설정되어있는 activity_main.xml 코드 :

그리고이 난 것입니다 시도 :

+0

당신은 당신이 사용하고있는 API를 wrap_content – geekCode

+0

를 사용해야합니까? –

+0

맞습니다. 그러나 API 레벨 14를 사용하고 있습니다 – bukk530

답변

1

TableLayoutTableRow은 모두 LinearLayouts입니다. 그래서 weight 속성을 사용하여 당신에게 원하는 결과를 줄 것이다 : 그들이 화면 높이 각의 50 %를 맞게 만들기 위해 TableRows에 대한 layout_height="0dp"layout_weight="0.5"을 설정 match_parent

    1. 설정 TableLayout's 폭과 높이를;
    2. 행의 높이를 채우기 위해 각 높이를 match_parent으로 설정하고 layout_width="0dp"layout_weight="0.5"을 행의 너비에 동일하게 맞 춥니 다. 여기

  • 레이아웃입니다 :

    <TableLayout xmlns:android="http://schemas.android.com/apk/res/android" 
        android:layout_width="match_parent" 
        android:layout_height="match_parent"> 
    
    <TableRow 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        android:layout_weight="0.5"> 
    
        <Button 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="0.5" 
         android:text="New Button" 
         android:id="@+id/button1" /> 
    
        <Button 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="0.5" 
         android:text="New Button" 
         android:id="@+id/button4" /> 
    </TableRow> 
    
    <TableRow 
        android:layout_width="wrap_content" 
        android:layout_height="0dp" 
        android:layout_weight="0.5"> 
    
        <Button 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="0.5" 
         android:text="New Button" 
         android:id="@+id/button2" /> 
    
        <Button 
         android:layout_width="0dp" 
         android:layout_height="match_parent" 
         android:layout_weight="0.5" 
         android:text="New Button" 
         android:id="@+id/button3" /> 
    </TableRow> 
    
    </TableLayout> 
    

    그리고 여기이 같은 모습입니다 : 당신이 fill_parent를 사용하는

    enter image description here

    +0

    예제를 복사했습니다. 작동하지 않습니다. 버튼에는 패딩이 있습니다. – Butsaty

    +0

    @Butsaty 당신을 보지 않고서는 정확한 레이아웃 XML은 "작동하지 않습니다"라는 것을 말하기 어렵습니다. 이 레이아웃은 질문 소유자에게 도움이되었습니다 ... 새로운 질문을하고 원할 경우 알려주십시오 - 질문을 살펴 보겠습니다. – Onik

    +0

    @Butsaty downvote 할 때, 정확히 무엇이 잘못되었는지 대답 해주십시오. 그렇지 않으면 잘못된 방식으로 대답을 사용했던 것은 당신이라는 의미 일 수 있습니다. 여기처럼, 예를 들어 패딩이 전혀 없으므로 코드에서 다른 패딩이 있어야합니다. – Onik