2015-04-17 51 views
3

我對如何增加我的TableLayout的整體寬度以便更接近屏幕兩側感到困惑。Android Eclipse - 增加我的桌面佈局的側邊距

我不確定我是否在實際的TableLayout本身或在其父RelativeLayout ...中調整了這一點?

圖片:

enter image description here

有什麼想法?

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
tools:context="com.example.funkycalc.MainActivtiy\" > 

<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" > 

    <TableRow 
     android:id="@+id/tableRow1" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button1" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_span="2" 
      android:text="CLR" /> 

     <Button 
      android:id="@+id/button2" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_span="2" 
      android:text="DEL" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button5" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="1" /> 

     <Button 
      android:id="@+id/button6" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="2" /> 

     <Button 
      android:id="@+id/button7" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="3" /> 

     <Button 
      android:id="@+id/button8" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="+" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button9" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="4" /> 

     <Button 
      android:id="@+id/button10" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="5" /> 

     <Button 
      android:id="@+id/button11" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="6" /> 

     <Button 
      android:id="@+id/button12" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="-" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button13" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="7" /> 

     <Button 
      android:id="@+id/button14" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="8" /> 

     <Button 
      android:id="@+id/button15" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="9" /> 

     <Button 
      android:id="@+id/button16" 
      style="?android:attr/buttonStyle" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="/" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow5" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button17" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_span="2" 
      android:text="0" /> 

     <Button 
      android:id="@+id/button18" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="." /> 

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

    <TableRow 
     android:id="@+id/tableRow6" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 

     <Button 
      android:id="@+id/button3" 
      style="?android:attr/buttonStyleSmall" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_span="4" 
      android:text="=" /> 
    </TableRow> 

    <TableRow 
     android:id="@+id/tableRow7" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" > 
    </TableRow> 

</TableLayout> 

<TextView 
    android:id="@+id/textView1" 
    android:layout_width="wrap_content" 
    android:layout_height="wrap_content" 
    android:layout_alignParentTop="true" 
    android:layout_centerHorizontal="true" 
    android:layout_marginTop="40dp" 
    android:text="Result" 
    android:textSize="55dp" /> 

回答

1

可以在表佈局使用match_parent所以需要父的整個寬度,則調節左右填充,以產生所希望的分離。請記住,您已經在相對佈局中定義了填充,因此您需要使用這兩個值。

<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:paddingLeft="10dp" 
    android:paddingRight="10dp" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" > 
+0

嘿軸,它開始工作,但仍然有一個問題......在tableLayout周邊(藍色)是完全我怎麼想它,但按鈕不填充空間!這是怎麼回事? – zombetelgeuse

+1

您的按鈕和行的寬度爲wrap_content。由於TableRow是一個LinearLayout,你應該能夠將按鈕寬度設置爲0,並將權重設置爲1,'android:layout_width ='0dp',android:layout_weight ='1''這樣按鈕將按比例提供所有可用空間。最後Tablerow應該使用'match_parent' – Axxiss

+0

Awx Axxiss,出色的建議。它幾乎在那裏......但是,我希望我的「0」按鈕顯示爲一個大按鈕,如張貼在我原始圖像的帖子中。我將如何做到這一點?我不認爲這是可能的寬度= 0和權重= 1 ... 你可以看到這裏的問題:http://i.imgur.com/SFlssjP.png – zombetelgeuse

0

您設置android:layout_width="wrap_content"到這會導致它只是寬度不足以顯示所有內容的TableLayout。嘗試使用match_parent,使其佔據整個父寬度:

<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" > 

一個日漸您TableLayout下來的另一件事情是這樣的:

android:paddingBottom="@dimen/activity_vertical_margin" 
android:paddingLeft="@dimen/activity_horizontal_margin" 
android:paddingRight="@dimen/activity_horizontal_margin" 
android:paddingTop="@dimen/activity_vertical_margin" 
RelativeLayout

。如果第一步不適合您的需求,您可以嘗試設置較低的值paddingLeftpaddingRight值。

0

試試這個編輯

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
xmlns:tools="http://schemas.android.com/tools" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 

tools:context="com.example.funkycalc.MainActivtiy\" > 

<TableLayout 
    android:id="@+id/tableLayout1" 
    android:layout_width="wrap_content" 
    android:layout_height="match_parent" 
    android:layout_alignParentBottom="true" 
    android:layout_centerHorizontal="true" > 

的填充值是問題...