如何修复滚动视图 android 底部的按钮?

Posted

技术标签:

【中文标题】如何修复滚动视图 android 底部的按钮?【英文标题】:How can I fix a button at the bottom in the scrollview android? 【发布时间】:2014-02-23 19:05:28 【问题描述】:

我有以下布局。

我有一个位于屏幕底部的按钮。

我已将表格布局放入滚动视图中,该滚动视图可以完美滚动。

但是使用滚动视图会使底部按钮消失。 我该如何解决它。

这是我的 xml 布局文件

   <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
 android:orientation="vertical" >

<LinearLayout
    android:layout_
    android:layout_
    android:layout_marginBottom="50dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="80dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_
        android:layout_
        android:gravity="center"
        android:text="Interest Rates on Domestic Term Deposits (w.e.f. 26th Septemr, 2013)"
        android:textColor="@color/White" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_
        android:layout_
        android:layout_weight="1" >

        <TableLayout
            android:layout_
            android:layout_ >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_
                android:layout_
                android:background="@color/Red"
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView2"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Pariculars"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView3"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="General"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Senior Citizens(p.a.)"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView3"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Revised for deposit upto"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Revised for deposit upto"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView5"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Revised for deposit upto"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView6"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Rs. 15 Lacs"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView7"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Rs. 15 Lacs"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView8"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Rs. 15 Lacs"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView9"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7days to 14 days"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView10"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7.25%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView11"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7.25%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow5"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView12"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="15 days to 90 days"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView13"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7.75%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView14"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7.75%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow6"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView15"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="91 days to 180 days"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView16"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="8.50%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView17"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="8.50%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow7"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView18"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="181 days to 12 months"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView19"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="9.50%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView20"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="9.50%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>
        </TableLayout>
    </ScrollView>
</LinearLayout>

<RelativeLayout
    android:layout_
    android:layout_
    android:gravity="bottom" >

    <Button
        android:id="@+id/homeInterestButton"
        android:layout_
        android:layout_
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Home" />
</RelativeLayout>

我只需要我的表格布局内容是可滚动的,并且主页按钮应该位于活动的底部。

【问题讨论】:

把RelativeLayout放在&lt;/ScrollView&gt;下面 FrameLayout 有两个孩子:一个 ScrollView 和一个 Button 是你的朋友 @RickFalck 已尝试但无法正常工作 @pskink RelativeLayout 有两个孩子:ScrollViewButton 是 OP 的最好的朋友。你的论点是无效的 ! xD @LittleChild RelativeLayout 在这种情况下更好吗?任何原因?速度?内存使用情况?还有其他的吗? 【参考方案1】:

为您的ScrollView 添加android:fillViewport="true" 属性。请参阅下面的代码。

<ScrollView
        android:id="@+id/scrollView1"
        android:layout_
        android:layout_
        android:fillViewport="true"
        android:layout_weight="1" >

还可以像下面这样更改代码。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_
    android:layout_
    android:orientation="vertical" >

    <LinearLayout
        android:layout_
        android:layout_
        android:layout_marginBottom="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="80dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_
            android:layout_
            android:gravity="center"
            android:text="Interest Rates on Domestic Term Deposits (w.e.f. 26th Septemr, 2013)"
            android:textColor="@color/White" />

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_
            android:layout_
            android:layout_weight="1" >

            <TableLayout
                android:layout_
                android:layout_ >

                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_
                    android:layout_
                    android:background="@color/Red"
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Pariculars"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="General"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Senior Citizens(p.a.)"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView5"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView6"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView7"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView8"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow4"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView9"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7days to 14 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView10"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.25%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView11"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.25%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow5"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView12"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="15 days to 90 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView13"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.75%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView14"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.75%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow6"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView15"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="91 days to 180 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView16"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="8.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView17"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="8.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow7"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView18"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="181 days to 12 months"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView19"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="9.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />

                    <TextView
                        android:id="@+id/textView20"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="9.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@color/White" />
                </TableRow>
            </TableLayout>
        </ScrollView>

        <RelativeLayout
            android:layout_
            android:layout_
            android:gravity="bottom" >

            <Button
                android:id="@+id/homeInterestButton"
                android:layout_
                android:layout_
                android:layout_alignParentBottom="true"
                android:layout_centerHorizontal="true"
                android:text="Home" />
        </RelativeLayout>
    </LinearLayout>
</LinearLayout>

【讨论】:

不工作。我只需要我的表格布局内容是可滚动的,并且主页按钮应该位于底部。【参考方案2】:

@Shink 检查这个从滚动视图中删除的重量——并将 0dp 替换为 wrap_content,将父级更改为相对布局,并且按钮没有其容器相对布局:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_
    android:layout_
    android:background="@android:color/darker_gray"
    android:orientation="vertical" >

    <LinearLayout
        android:layout_
        android:layout_
        android:layout_marginBottom="50dp"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="80dp"
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_
            android:layout_
            android:gravity="center"
            android:text="Interest Rates on Domestic Term Deposits (w.e.f. 26th Septemr, 2013)"
            android:textColor="@android:color/white" />

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_
            android:layout_ >

            <TableLayout
                android:layout_
                android:layout_ >

                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_
                    android:layout_
                    android:background="@android:color/black"
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Pariculars"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="General"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Senior Citizens(p.a.)"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView5"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView6"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView7"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView8"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow4"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView9"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7days to 14 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView10"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.25%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView11"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.25%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow5"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView12"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="15 days to 90 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView13"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.75%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView14"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.75%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow6"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView15"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="91 days to 180 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView16"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="8.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView17"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="8.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow7"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView18"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="181 days to 12 months"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView19"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="9.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView20"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="9.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>
            </TableLayout>
        </ScrollView>
    </LinearLayout>

    <Button
        android:id="@+id/homeInterestButton"
        android:layout_
        android:layout_
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Home" />

</RelativeLayout>

【讨论】:

【参考方案3】:

在 2nd Top Linear 布局中放入 2 行以下,就完成了:

        android:layout_
        android:layout_weight="1"

简而言之,您要做的就是将以下 xml 放入您的项目中并运行它。

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_
    android:layout_
    android:orientation="vertical"
    android:background="#000" >

    <LinearLayout
        android:layout_
        android:layout_
        android:layout_weight="1"
        android:layout_marginLeft="10dp"
        android:layout_marginRight="10dp"
        android:layout_marginTop="80dp"
        android:layout_marginBottom="50dp" 
        android:orientation="vertical" >

        <TextView
            android:id="@+id/textView1"
            android:layout_
            android:layout_
            android:gravity="center"
            android:text="Interest Rates on Domestic Term Deposits (w.e.f. 26th Septemr, 2013)"
            android:textColor="@android:color/white" />

        <ScrollView
            android:id="@+id/scrollView1"
            android:layout_
            android:layout_
            android:layout_weight="1" >

            <TableLayout
                android:layout_
                android:layout_ >

                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_
                    android:layout_
                    android:background="#900"
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Pariculars"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="General"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Senior Citizens(p.a.)"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow2"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView5"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Revised for deposit upto"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow3"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView6"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView7"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView8"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Rs. 15 Lacs"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow4"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView9"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7days to 14 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView10"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.25%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView11"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.25%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow5"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView12"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="15 days to 90 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView13"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.75%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView14"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="7.75%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow6"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView15"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="91 days to 180 days"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView16"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="8.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView17"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="8.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>

                <TableRow
                    android:id="@+id/tableRow7"
                    android:layout_
                    android:layout_
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView18"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="181 days to 12 months"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView19"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="9.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView20"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="9.50%"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>
                <TableRow
                    android:id="@+id/tableRow1"
                    android:layout_
                    android:layout_
                    android:background="#900"
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Pariculars"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="General"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Senior Citizens(p.a.)"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow><TableRow
                    android:id="@+id/tableRow1"
                    android:layout_
                    android:layout_
                    android:background="#900"
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Pariculars"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="General"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Senior Citizens(p.a.)"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow><TableRow
                    android:id="@+id/tableRow1"
                    android:layout_
                    android:layout_
                    android:background="#900"
                    android:gravity="center" >

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Pariculars"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView3"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="General"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />

                    <TextView
                        android:id="@+id/textView4"
                        android:layout_
                        android:layout_
                        android:layout_weight="1"
                        android:gravity="center"
                        android:text="Senior Citizens(p.a.)"
                        android:textAppearance="?android:attr/textAppearanceSmall"
                        android:textColor="@android:color/white" />
                </TableRow>
            </TableLayout>
        </ScrollView>
    </LinearLayout>

    <RelativeLayout
        android:layout_
        android:layout_
         android:gravity="center">

        <Button
            android:id="@+id/homeInterestButton"
            android:layout_
            android:layout_
            android:text="Home" />
    </RelativeLayout>

</RelativeLayout>

【讨论】:

【参考方案4】:

希望这对你有用:

  <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_
android:layout_
 android:orientation="vertical" >

<LinearLayout
    android:layout_
    android:layout_
    android:layout_marginBottom="50dp"
    android:layout_marginLeft="10dp"
    android:layout_marginRight="10dp"
    android:layout_marginTop="80dp"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/textView1"
        android:layout_
        android:layout_
        android:gravity="center"
        android:text="Interest Rates on Domestic Term Deposits (w.e.f. 26th Septemr, 2013)"
        android:textColor="@color/White" />

    <ScrollView
        android:id="@+id/scrollView1"
        android:layout_
        android:layout_
        android:layout_weight="1" >

        <TableLayout
            android:layout_
            android:layout_ >

            <TableRow
                android:id="@+id/tableRow1"
                android:layout_
                android:layout_
                android:background="@color/Red"
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView2"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Pariculars"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView3"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="General"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Senior Citizens(p.a.)"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow2"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView3"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Revised for deposit upto"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView4"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Revised for deposit upto"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView5"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Revised for deposit upto"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow3"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView6"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Rs. 15 Lacs"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView7"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Rs. 15 Lacs"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView8"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="Rs. 15 Lacs"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow4"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView9"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7days to 14 days"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView10"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7.25%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView11"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7.25%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow5"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView12"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="15 days to 90 days"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView13"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7.75%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView14"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="7.75%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow6"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView15"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="91 days to 180 days"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView16"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="8.50%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView17"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="8.50%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>

            <TableRow
                android:id="@+id/tableRow7"
                android:layout_
                android:layout_
                android:gravity="center" >

                <TextView
                    android:id="@+id/textView18"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="181 days to 12 months"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView19"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="9.50%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />

                <TextView
                    android:id="@+id/textView20"
                    android:layout_
                    android:layout_
                    android:layout_weight="1"
                    android:gravity="center"
                    android:text="9.50%"
                    android:textAppearance="?android:attr/textAppearanceSmall"
                    android:textColor="@color/White" />
            </TableRow>
            <RelativeLayout
    android:layout_
    android:layout_
    android:gravity="bottom" >

    <Button
        android:id="@+id/homeInterestButton"
        android:layout_
        android:layout_
        android:layout_alignParentBottom="true"
        android:layout_centerHorizontal="true"
        android:text="Home" />
</RelativeLayout>
        </TableLayout>
    </ScrollView>
</LinearLayout>

</LinearLayout>

【讨论】:

不工作。我只需要我的表格布局内容是可滚动的,并且主页按钮应该出现在屏幕底部。【参考方案5】:

好吧,你需要把你的按钮放在ScrollView之外。因此将需要另一层嵌套。将您的ScrollView 放入RelativeLayout(或LinearLayout),将按钮放在底部。这样,当项目添加到 ScrollView 时,它不会向下滚动

<RelativeLayout ...>

    <ScrollView android:id="@+id/scroll"...>
        <!-- The child of ScrollView -->
    </ScrollView>

    <Button android:layout_alignParentBottom = "true"
        android:layout_below="@id/scroll" />

</RelativeLayout>

【讨论】:

我没听懂你...你能简单介绍一下吗【参考方案6】:

您的根布局是 LinearLayout。为您的按钮布局赋予 0 权重,并赋予其他布局权重 1。它应该可以完成这项工作。

【讨论】:

它的行为是什么?可以发截图吗?

以上是关于如何修复滚动视图 android 底部的按钮?的主要内容,如果未能解决你的问题,请参考以下文章

如何获取滚动视图的滚动量

Android:滚动图像视图

如何在 Swiftui 的主视图底部的滚动视图中放置一个非粘性按钮? Spacer 在滚动视图中似乎没有效果

滚动视图底部的按钮不响应

Android ScrollView 自动滚动到视图底部

在滚动上隐藏/显示底部导航视图