Android TableLayout:按钮必须粘在一起而不留任何空间

Android TableLayout:按钮必须粘在一起而不留任何空间,android,button,Android,Button,我做了一个选项卡栏。它显示在屏幕底部。然后我 创建了五个按钮,显示在屏幕底部 在选项卡栏上方 您可以看到下图: 下面是我发布的代码: main.xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android

我做了一个选项卡栏。它显示在屏幕底部。然后我 创建了五个按钮,显示在屏幕底部 在选项卡栏上方

  • 您可以看到下图:

  • 下面是我发布的代码:
  • main.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" >
    
        <TabHost
            android:id="@android:id/tabhost"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" >
    
            <LinearLayout
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:orientation="vertical" >
    
                <FrameLayout
                    android:id="@android:id/tabcontent"
                    android:layout_width="fill_parent"
                    android:layout_height="0dip"
                    android:layout_weight="5" >
                </FrameLayout>
    
                  <TableLayout 
                      android:layout_width="fill_parent"
                      android:layout_height="wrap_content"
                      android:orientation="vertical" 
                      >
    
                      <TableRow
                          android:layout_width="wrap_content"
                          android:layout_height="wrap_content"
                          android:orientation="horizontal" >
    
                          <Button
                              android:id="@+id/button1"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:text="BOOKS" />
    
                          <Button
                              android:id="@+id/button2"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:text="LIBRARY" />
    
                          <Button
                              android:id="@+id/button3"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:text="MATH" />
    
                          <Button
                              android:id="@+id/button4"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:text="MUSEUM" />
    
                          <Button
                              android:id="@+id/button5"
                              android:layout_width="wrap_content"
                              android:layout_height="wrap_content"
                              android:text="+24" />
                      </TableRow>
    
                     </TableLayout>
    
    
                <TabWidget
                    android:id="@android:id/tabs"
                    android:layout_width="fill_parent"
                    android:layout_height="wrap_content"
                    android:layout_weight="0" />
            </LinearLayout>
        </TabHost>
    
    </LinearLayout>
    
    
    

    我的问题是按钮必须粘在一起而不留下任何空间。任何人都可以帮我。谢谢。

    有一个棘手的解决方案

    您只需为其设置负边距
    只需将第一个按钮的
    android:layout_marginRight
    设置为“-7dip”甚至更高

    尝试编写如下代码。。。 根据需要设置边距

        <TableLayout
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:orientation="vertical" >
    
            <TableRow
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:orientation="horizontal" >
    
                <Button
                    android:id="@+id/button1"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-7dip"
                    android:text="BOOKS" />
    
                <Button
                    android:id="@+id/button2"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-7dip"
                    android:text="LIBRARY" />
    
                <Button
                    android:id="@+id/button3"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-7dip"
                    android:text="MATH" />
    
                <Button
                    android:id="@+id/button4"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-7dip"
                    android:text="MUSEUM" />
    
                <Button
                    android:id="@+id/button5"
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:layout_marginRight="-7dip"
                    android:text="+24" />
            </TableRow>
        </TableLayout>
    
    
    
    同样是你。很好。再次感谢你。这绝对是一个棘手的解决方案。@Aniruddha:它应该适用于所有设备……无论是棘手的……你不能确定。。