0

I am trying to attach a TableLayout into my Navigation drawer activity. The TableLayout should not show when I click the menu items. This is my XML file:

    <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.DrawerLayout
         xmlns:android="http://schemas.android.com/apk/res/android"
         xmlns:app="http://schemas.android.com/apk/res-auto"
         xmlns:tools="http://schemas.android.com/tools"
         android:layout_width="match_parent"
         android:layout_height="match_parent"
         android:id="@+id/drawer_layout"
         android:fitsSystemWindows="true"
         tools:context=".Homepage"
         tools:openDrawer="start">

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:orientation="vertical">

            <android.support.v7.widget.Toolbar
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@color/colorPrimary"
                android:id="@+id/toolbar"
                android:theme="@style/ThemeOverlay.AppCompat.ActionBar"
                app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
                android:elevation="4dp"/>
            <TableLayout
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:background="#CCC"
                android:layout_marginTop="50pt"
                android:paddingTop="1dp"
                android:stretchColumns="0"
                android:id="@+id/tlTable01">

                <TableRow
                    android:background="#CCC"
                    android:paddingBottom="1dp"
                    android:paddingRight="1dp">
                    <TextView
                        android:layout_marginLeft="1dp"
                        android:padding="5dp"
                        android:background="#FFF"
                        android:text="Total quarters registered"/>
                    <TextView
                        android:layout_marginLeft="1dp"
                        android:padding="5dp"
                        android:background="#FFF"
                        android:gravity="right"
                        android:id="@+id/noqrtrreg"
                        android:text="123456"/>
                </TableRow>
                <TableRow
                    android:background="#CCC"
                    android:paddingBottom="1dp"
                    android:paddingRight="1dp">
                    <TextView
                        android:layout_marginLeft="1dp"
                        android:padding="5dp"
                        android:background="#FFF"
                        android:text="Total quarters occupied"/>
                    <TextView
                        android:layout_marginLeft="1dp"
                        android:padding="5dp"
                        android:background="#FFF"
                        android:gravity="right"
                        android:id="@+id/noqrtrocc"
                        android:text="456789"/>
                </TableRow>
                <TableRow
                    android:background="#CCC"
                    android:paddingBottom="1dp"
                    android:paddingRight="1dp">
                    <TextView
                        android:layout_marginLeft="1dp"
                        android:padding="5dp"
                        android:background="#FFF"
                        android:text="Total meter charge calculated till date"/>
                    <TextView
                        android:layout_marginLeft="1dp"
                        android:padding="5dp"
                        android:background="#FFF"
                        android:gravity="right"
                        android:id="@+id/totmetchrg"
                        android:text="456789"/>
                </TableRow>
            </TableLayout>
            <FrameLayout
                android:id="@+id/fragment_container"
                android:layout_width="match_parent"
                android:layout_height="match_parent"/>

        </LinearLayout>
    <android.support.design.widget.NavigationView
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:id="@+id/nav_view"
        app:headerLayout="@layout/nav_header"
        app:menu="@menu/drawer_menu"/>
</android.support.v4.widget.DrawerLayout>

For some reason, the table is visible even when I click on any menu items, I want it to be visible only in the main page. How do I do that?

2 Answers2

0

"pt" is not recognized by android.

<TableLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:background="#CCC"
    android:layout_marginTop="50dp" <!--dp instead of pt-->
    android:paddingTop="1dp"
    android:stretchColumns="0"
    android:id="@+id/tlTable01">
Kristy Welsh
  • 7,828
  • 12
  • 64
  • 106
0

edit: looks like op wrongly implemented DrawerLayout, I'm suggesting to read again doc a do it as it should be

pt isn't a proper unit in here, quoting from DOC 1pt is

1/72 of an inch based on the physical size of the screen

just use dp like in other attributes

android:layout_marginTop="50dp"

check out all available units and differences between them in HERE

snachmsm
  • 17,866
  • 3
  • 32
  • 74
  • Still not working, the table remains fixed at the top –  Feb 24 '22 at 11:56
  • now I've noticed that your code have plenty of mistakes... please read again how to use `DrawerLayout`, but in short: it should contain only two childs. your ` – snachmsm Feb 24 '22 at 12:02
  • should it be below `DrawerLayout`? –  Feb 24 '22 at 13:02
  • I don't know, you didn't described where you want it to be... for shoure it shouldn'b be placed as third child of `NavigationView`. probably inside `fragment_container`, but according to naming - you are loading `Fragment`s in there... so maybe this table should be a part of `Fragment`? all is guessing as you didn't described what you want to achieve – snachmsm Feb 24 '22 at 13:08
  • I want it below the toolbar, I tried moving the code below the `FrameLayout`, but now the table doesn't even show –  Feb 24 '22 at 13:57
  • so place it below `Toolbar` and above `FrameLayout` (remember to keep `layout_height="wrap_content"` for `TableLayout`) – snachmsm Feb 24 '22 at 14:00
  • Tried it, now the `TableLayout` shows up even when I click on the navigation menu items. I want it to be visible only in the first page. –  Feb 25 '22 at 04:57
  • so it should be a part of first `Fragment`, thats obvius.. – snachmsm Feb 25 '22 at 07:26