如何将拆分布局放在 table 标题下方?

How to place the splitting layout below the table heading?

我想在标题栏上方放置一个文本。但问题是,即使我放置了权重,我也无法将 "Registrai text" 与相应的标题栏对齐。

这是我试过的代码。

     <?xml version="1.0" encoding="utf-8"?>
    <android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
        xmlns:app="http://schemas.android.com/apk/res-auto"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/colorWhite"
        android:isScrollContainer="false">

//this layout is not aligning properly with corresponding titles.

            <LinearLayout
                android:id="@+id/rel0"
                android:layout_width="match_parent"
                android:layout_height="33dp"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:layout_marginTop="14dp"
                android:gravity="center_vertical"
                android:weightSum="10">

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_alignParentLeft="true"
                    android:layout_weight="2.5"
                    android:gravity="center"
                    android:text="14.30WIB"
                    android:textColor="@color/colorBlack"
                    android:textSize="14sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.5"
                    android:gravity="center"
                    android:text="Sell in"
                    android:textColor="@color/colorBlack"
                    android:textSize="10sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2"
                    android:gravity="center"
                    android:text="Sell in"
                    android:textColor="@color/colorBlack"
                    android:textSize="10sp" />

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

                    <TextView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:text="Registrasi"
                        android:textColor="@color/colorBlack"
                        android:textSize="10sp" />

                    <LinearLayout
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:orientation="horizontal">

                        <TextView
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1.2"
                            android:gravity="center"
                            android:text="New"
                            android:textColor="@color/colorBlack"
                            android:textSize="10sp" />

                        <TextView
                            android:layout_width="0dp"
                            android:layout_height="match_parent"
                            android:layout_weight="1.2"
                            android:gravity="center"
                            android:text="Re"
                            android:textColor="@color/colorBlack"
                            android:textSize="10sp" />
                    </LinearLayout>
                </LinearLayout>


                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2"
                    android:gravity="center"
                    android:text="Edukasi"
                    android:textColor="@color/colorBlack"
                    android:textSize="8sp" />

                <TextView
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2"
                    android:gravity="center"
                    android:text="POSM"
                    android:textColor="@color/colorBlack"
                    android:textSize="8sp" />

            </LinearLayout>

      <LinearLayout
                android:id="@+id/rel1"
                android:layout_width="match_parent"
                android:layout_height="33dp"
                android:layout_below="@+id/rel0"
                android:layout_marginLeft="10dp"
                android:layout_marginRight="10dp"
                android:background="@drawable/nbd_title"
                android:gravity="center_vertical"
                android:weightSum="10">

                <TextView
                    android:id="@+id/siteId"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_alignParentLeft="true"
                    android:layout_weight="2.5"
                    android:gravity="center"
                    android:text="Total"
                    android:textColor="@color/colorWhite"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/site"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.5"
                    android:gravity="center"
                    android:text="XXXXX"
                    android:textColor="@color/colorWhite"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/twoG"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2"
                    android:gravity="center"
                    android:text="XXX"
                    android:textColor="@color/colorWhite"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/threeG"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2"
                    android:gravity="center"
                    android:text="XXX"
                    android:textColor="@color/colorWhite"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/fourG"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2"
                    android:gravity="center"
                    android:text="XXX"
                    android:textColor="@color/colorWhite"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/retailerId"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2"
                    android:gravity="center"
                    android:text="XXX"
                    android:textColor="@color/colorWhite"
                    android:textSize="12sp" />

                <TextView
                    android:id="@+id/idealId"
                    android:layout_width="0dp"
                    android:layout_height="match_parent"
                    android:layout_weight="1.2"
                    android:gravity="center"
                    android:text="XXX"
                    android:textColor="@color/colorWhite"
                    android:textSize="12sp" />

            </LinearLayout>
          </LinearLayout>
</android.support.v4.widget.NestedScrollView>

我的输出看起来像这样,没有与相应的标题正确对齐。

实际输出:(您可以看到注册文本在相应标题栏上方分成两部分的位置。但我无法使用它)

不对的地方请指正

你错误地使用了权重。在这里修复它。

<android.support.v4.widget.NestedScrollView
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:isScrollContainer="false">

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

        <LinearLayout
            android:id="@+id/rel0"
            android:layout_width="match_parent"
            android:layout_height="33dp"
            android:gravity="center_vertical"
            android:weightSum="10">

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_weight="2.5"
                android:gravity="center"
                android:text="14.30WIB"
                android:textSize="14sp" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.5"
                android:gravity="center"
                android:text="Sell in"
                android:textSize="10sp" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.2"
                android:gravity="center"
                android:text="Sell in"
                android:textSize="10sp" />

            <LinearLayout
                android:layout_width="0dp"
                android:layout_weight="2.4"
                android:layout_height="wrap_content"
                android:orientation="vertical">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:gravity="center"
                    android:text="Registrasi"
                    android:textSize="10sp" />

                <LinearLayout
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:orientation="horizontal">

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="New"
                        android:textSize="10sp" />

                    <TextView
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Re"
                        android:textSize="10sp" />
                </LinearLayout>
            </LinearLayout>


            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.2"
                android:gravity="center"
                android:text="Edukasi"
                android:textSize="8sp" />

            <TextView
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.2"
                android:gravity="center"
                android:text="POSM"
                android:textSize="8sp" />

        </LinearLayout>

        <LinearLayout
            android:id="@+id/rel1"
            android:layout_width="match_parent"
            android:layout_height="33dp"
            android:layout_below="@+id/rel0"
            android:gravity="center_vertical"
            android:weightSum="10">

            <TextView
                android:id="@+id/siteId"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_alignParentLeft="true"
                android:layout_weight="2.5"
                android:gravity="center"
                android:text="Total"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/site"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.5"
                android:gravity="center"
                android:text="XXXXX"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/twoG"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.2"
                android:gravity="center"
                android:text="XXX"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/threeG"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.2"
                android:gravity="center"
                android:text="XXX"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/fourG"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.2"
                android:gravity="center"
                android:text="XXX"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/retailerId"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.2"
                android:gravity="center"
                android:text="XXX"
                android:textSize="12sp" />

            <TextView
                android:id="@+id/idealId"
                android:layout_width="0dp"
                android:layout_height="match_parent"
                android:layout_weight="1.2"
                android:gravity="center"
                android:text="XXX"
                android:textSize="12sp" />

        </LinearLayout>
    </LinearLayout>
</android.support.v4.widget.NestedScrollView>

你必须用下面的代码替换你的...工作正常..它会帮助你..

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.NestedScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorWhite"
    android:isScrollContainer="false">

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

    <LinearLayout
        android:id="@+id/rel0"
        android:layout_width="match_parent"
        android:layout_height="33dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="14dp"
        android:gravity="center_vertical"
        android:weightSum="10">

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_weight="2.5"
            android:gravity="center"
            android:text="14.30WIB"
            android:textColor="@color/colorBlack"
            android:textSize="14sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.5"
            android:gravity="center"
            android:text="Sell in"
            android:textColor="@color/colorBlack"
            android:textSize="10sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.2"
            android:gravity="center"
            android:text="Sell in"
            android:textColor="@color/colorBlack"
            android:textSize="10sp" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:orientation="vertical"
            android:layout_weight="2.4">

            <TextView
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:text="Registrasi"
                android:gravity="center"
                android:textColor="@color/colorBlack"
                android:textSize="10sp" />

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="horizontal">

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="New"
                    android:textColor="@color/colorBlack"
                    android:textSize="10sp" />

                <TextView
                    android:layout_width="match_parent"
                    android:layout_height="match_parent"
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Re"
                    android:textColor="@color/colorBlack"
                    android:textSize="10sp" />
            </LinearLayout>
        </LinearLayout>


        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.2"
            android:gravity="center"
            android:text="Edukasi"
            android:textColor="@color/colorBlack"
            android:textSize="8sp" />

        <TextView
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.2"
            android:gravity="center"
            android:text="POSM"
            android:textColor="@color/colorBlack"
            android:textSize="8sp" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/rel1"
        android:layout_width="match_parent"
        android:layout_height="33dp"
        android:layout_below="@+id/rel0"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:background="#478387"
        android:gravity="center_vertical"
        android:weightSum="10">

        <TextView
            android:id="@+id/siteId"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_alignParentLeft="true"
            android:layout_weight="2.5"
            android:gravity="center"
            android:text="Total"
            android:textColor="@color/colorWhite"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/site"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.5"
            android:gravity="center"
            android:text="XXXXX"
            android:textColor="@color/colorWhite"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/twoG"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.2"
            android:gravity="center"
            android:text="XXX"
            android:textColor="@color/colorWhite"
            android:textSize="12sp" />

        <LinearLayout
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="2.4"
            android:orientation="horizontal"
            android:weightSum="2">

        <TextView
            android:id="@+id/threeG"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="XXX"
            android:textColor="@color/colorWhite"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/fourG"
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_weight="1"
            android:gravity="center"
            android:text="XXX"
            android:textColor="@color/colorWhite"
            android:textSize="12sp" />

        </LinearLayout>

        <TextView
            android:id="@+id/retailerId"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.2"
            android:gravity="center"
            android:text="XXX"
            android:textColor="@color/colorWhite"
            android:textSize="12sp" />

        <TextView
            android:id="@+id/idealId"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.2"
            android:gravity="center"
            android:text="XXX"
            android:textColor="@color/colorWhite"
            android:textSize="12sp" />

    </LinearLayout>

    </LinearLayout>

    </android.support.v4.widget.NestedScrollView>