简体   繁体   中英

TableLayout: Buttons have to stick together without leaving any space

  • I done a Tab Bar.It displays at the bottom of the screen.Then I created five buttons.That was displayed at the bottom of the screen above the tab bar.

  • You can see the image below:

    在此处输入图片说明

  • Below I am posted the codes:

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>

My problem is Buttons have to stick together without leaving any space.Anybody can help me with these.Thank you.

There is Tricky Solution For it...

You Just Have to Set Negative Margins For it....
Just set the android:layout_marginRight of the first button to "-7dip" or even more.

Try Code Something like below... Set Margins As Your Need

    <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>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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