繁体   English   中英

TableLayout:按钮必须粘在一起而没有任何空间

[英]TableLayout: Buttons have to stick together without leaving any space

  • 我完成了一个标签栏,它显示在屏幕底部,然后创建了五个按钮,显示在标签栏上方的屏幕底部。

  • 您可以看到下图:

    在此处输入图片说明

  • 以下是我张贴的代码:

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>

我的问题是Button必须贴在一起而不留任何空间,任何人都可以帮助我,谢谢。

有棘手的解决方案...

您只需要为此设置负边距即可
只需将第一个按钮的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>

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM