2012-04-30 76 views
2

enter image description here 我正在使用表格布局。我想要的是平等地将屏幕左侧垂直布局(表格布局)中看到的图标间隔开,以覆盖整个屏幕的高度。我尝试了不同的方法,如layout_weight =“1”,将图像宽度设置为0dp,然后设置重量...但其中没有一个帮助.....表格布局间距问题

这里是xml ...

<TableLayout 
       android:id="@+id/tableLayout1" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent" 

       android:layout_marginTop="50dp" > 

       <TableRow 
        android:layout_weight="1" 
       > 
        <Button 
       android:id="@+id/button1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content"          
       android:background="@drawable/XXX" /> 
       </TableRow> 

       <TableRow 
        android:layout_weight="1" 
        > 
       <TextView 
       android:id="@+id/textView1" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Desserts" 
       /> 
        </TableRow> 

        <TableRow 
        android:layout_weight="1" 
        > 
        <Button 
       android:id="@+id/button2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:background="@drawable/sraberrydrink" /> 
        </TableRow> 

        <TableRow 
        android:layout_weight="1" 
        > 
        <TextView 
       android:id="@+id/textView2" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:text="Drinks" 
       android:textColor="#000000"    
       android:textSize="10dp" /> 
        </TableRow> 

        <TableRow 
        android:layout_weight="1" 
        > 

        <Button 
       android:id="@+id/button3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 

       android:background="@drawable/newsoups" /> 
        </TableRow> 
       <TableRow 
        android:layout_weight="1" 
        > 
        <TextView 
       android:id="@+id/textView3" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="45dp" 
       android:text="Starters" 
       android:textColor="#000000" 
       android:textSize="10dp" /> 

        </TableRow> 
        <TableRow 
         android:layout_weight="1" > 

      <Button 
      android:id="@+id/button4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:layout_marginLeft="40dp" 
      android:layout_marginTop="3dp" 

      android:background="@drawable/chipa" /> 
        </TableRow> 
        <TableRow 
        android:layout_weight="1" 
        > 
       <TextView 
      android:id="@+id/textView4" 
      android:layout_width="wrap_content" 
      android:layout_height="wrap_content" 
      android:text="Snacks" 
      android:layout_marginLeft="45dp" 
      android:textColor="#000000" 
      android:textSize="10dp"/> 
       </TableRow> 


      </TableLayout> 

如果有人可以指出解决方案....谢谢。

+0

我一直在尝试了一点;似乎在任何单元格中使用layout_weight都会完全破坏列对齐。 –

回答

0

enter image description here

你可以做的是可以使用线性布局像这样

!<?xml version="1.0" encoding="utf-8"?> 
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/layout_main" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" > 

    <LinearLayout 
    android:id="@+id/layout_main" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" android:background="#2e8b57" android:layout_weight=".8" android:gravity="center"> 

    <LinearLayout 
    android:id="@+id/layout_main" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" android:layout_weight=".5"> 

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

     <LinearLayout 
    android:id="@+id/layout_main" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" android:layout_weight=".5"> 
    <Button 
     android:id="@+id/button2" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 
</LinearLayout> 

       <LinearLayout 
    android:id="@+id/layout_main" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" android:layout_weight=".5"> 
    <Button 
     android:id="@+id/button3" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 
</LinearLayout> 

        <LinearLayout 
    android:id="@+id/layout_main" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" android:layout_weight=".5"> 
    <Button 
     android:id="@+id/button4" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Button" /> 

    </LinearLayout> 
    </LinearLayout> 

     <LinearLayout 
    android:id="@+id/layout_main" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="vertical" 
    android:background="#8fbc8f" android:layout_weight=".2"> 
      <LinearLayout 
    android:id="@+id/layout_main" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" android:layout_weight=".8" android:gravity="center"> 



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

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

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



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


    </LinearLayout> 

       <LinearLayout 
    android:id="@+id/layout_main" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:orientation="horizontal" android:layout_weight=".8" android:gravity="top|center"> 



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

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

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

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


    </LinearLayout> 
      </LinearLayout> 
</LinearLayout> 
+0

Avi,是的......你说得对......已经使用了线性布局,但是有一个需要使用表格布局.........所以有什么可能的表格布局? –

+0

@KunalShah我已经上传了一张图片作为你的布局,如果你觉得它很好或者你仍然需要使用表格布局 –

+0

嗯mmmmm ......这很好......还有avi一个疑问....如何支持这在多个屏幕上...随着android调整资源,它会工作吗? –