如何在相对布局中添加固定标题和滚动视图表行?

     2023-04-19     287

关键词:

【中文标题】如何在相对布局中添加固定标题和滚动视图表行?【英文标题】:How to add fixed header and scrollview table rows in relativelayout? 【发布时间】:2021-12-29 02:13:54 【问题描述】:

我的目的是用可滚动的行固定表头,以便用户在表内添加值时表头可以稳定。如何在表格标题后的表格行内添加滚动视图,这是我的代码,

activity.xml:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_
android:layout_
tools:context=".MainActivity">

<TableLayout
    android:layout_
    android:layout_
    android:background="@android:color/white"
    android:layout_margin="40dp">

    <TableRow
        android:layout_
        android:background="@color/colorGreen">

        <TextView
            android:layout_
            android:layout_
            android:layout_weight="2"
            android:gravity="center_horizontal"
            android:padding="10sp"
            android:text="Department"
            android:textColor="@android:color/white"
            android:textSize="14sp" />
    </TableRow>
    <TableRow>
        <TextView
            android:text="B.E/B.Tech"
            android:layout_
            android:layout_
            android:layout_weight="2"
            android:gravity="center_horizontal"
            android:padding="10sp"
            android:textSize="15sp" />
    </TableRow>
    <TableRow>
        <TextView
            android:text="M.E/M.Tech"
            android:layout_
            android:layout_
            android:layout_weight="2"
            android:gravity="center_horizontal"
            android:padding="10sp"
            android:textSize="15sp" />
    </TableRow>
  </TableLayout>
</RelativeLayout>

【问题讨论】:

你能添加一张你需要的粗略图表吗? 【参考方案1】:

最简单的方法是将标题/标题放在TableLayout之外,然后需要将TableLayout包裹在ScrollView

我对你的代码做了一些修改

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_
    android:layout_
    tools:context=".ui.TableActivity">

    <TextView
        android:id="@+id/title"
        android:layout_
        android:layout_
        android:padding="10dp"
        android:layout_centerHorizontal="true"
        android:gravity="center_horizontal"
        android:layout_margin="40dp"
        android:text="Department"
        android:background="@color/design_default_color_primary"
        android:textColor="@android:color/white"
        android:textSize="14sp" />

    <ScrollView
        android:layout_
        android:layout_
        android:layout_below="@id/title">

        <TableLayout
            android:layout_
            android:layout_
            android:background="@android:color/white"
            android:layout_margin="40dp">
            <TableRow>
                <TextView
                    android:text="B.E/B.Tech"
                    android:layout_
                    android:layout_
                    android:layout_weight="2"
                    android:gravity="center_horizontal"
                    android:padding="10dp"
                    android:textSize="15sp" />
            </TableRow>
            <TableRow>
                <TextView
                    android:text="M.E/M.Tech"
                    android:layout_
                    android:layout_
                    android:layout_weight="2"
                    android:gravity="center_horizontal"
                    android:padding="10dp"
                    android:textSize="15sp" />
            </TableRow>
        </TableLayout>
    </ScrollView>
</RelativeLayout>

无论如何,如果希望显示数据列表,我认为您应该考虑使用RecyclerView。由于RecyclerView 是处理数据列表的推荐方式

【讨论】:

滚动视图必须发生在第 1 行之后。即,固定页眉[tablerow1] 和可滚动页脚[剩余的 tablerow] 当前答案应该如你所愿

html中table表格标题固定表数据行出现滚动条

...样比较人性化。二、js方法(需要和三、页面中的div和table布局配套使用。div和table的id已经被指定)备注:使用此方法,需要j 查看详情

如何知道在相对布局中单击了哪个子视图

】如何知道在相对布局中单击了哪个子视图【英文标题】:Howtoknowwhichchildviewisclickedinarelativelayout【发布时间】:2016-06-0810:25:29【问题描述】:我有一个动态添加和删除子视图的相对布局(可以添加或删除任何数量)我的问题是... 查看详情

UITableView - 如何在用户滚动时保持表格行固定

】UITableView-如何在用户滚动时保持表格行固定【英文标题】:UITableView-Howtokeeptablerowsfixedasuserscrolls【发布时间】:2012-06-0508:50:28【问题描述】:我希望能够在用户滚动时修复UITableView中某些行的位置。具体来说,我有一个表格,... 查看详情

添加文本和禁用滚动时如何使 UITextView 字段扩展?

】添加文本和禁用滚动时如何使UITextView字段扩展?【英文标题】:HowdoIgetUITextViewfieldtoexpandwhenaddingtextandscrollingisdisabled?【发布时间】:2018-08-1517:36:17【问题描述】:我在tableView单元格中使用UITextView来保存不同大小的文本内容,... 查看详情

如何实现在动态布局中添加更多视图在android中实现滚动视图

】如何实现在动态布局中添加更多视图在android中实现滚动视图【英文标题】:howcanimplementedaddingmoreviewsindynamiclayoutimplementingscrollviewinandroid【发布时间】:2011-04-0816:29:45【问题描述】:我正在实现自定义线性布局,在此添加更多... 查看详情

分页滚动视图约束布局问题

】分页滚动视图约束布局问题【英文标题】:PagingScrollViewconstraintslayoutissue【发布时间】:2019-10-1208:26:33【问题描述】:在项目中,我创建了基于约束的分页滚动视图。大部分视图是在xib中设置的(SlideViewController.和UIView的SlideVie... 查看详情

前端3浮动布局,固定定位,绝对定位,相对定位

...,父级的兄弟标签就会上移被覆盖定位布局:固定定位:盒子相对于屏幕完成位置布局,不会随着屏幕内容的滚动而滚动(相对于屏幕窗口是静止的)且和页面内容发生重叠时,该布局下的内容显示层次更高(覆盖其他内容)语法:position:fixed... 查看详情

仅在自动布局中具有固定宽度的垂直滚动视图

...dthinAutolayout【发布时间】:2015-02-0622:27:10【问题描述】:如何快速将滚动视图的宽度设置为屏幕大小的宽度?我尝试设置正确的前后边界,但我的aspectscalefill图像一直在拉伸整个帧。我试图将视图强制为屏幕宽度并只允许垂直滚... 查看详情

如何在 Gatsby 的标题中添加滚动事件

】如何在Gatsby的标题中添加滚动事件【英文标题】:HowtoaddascrolleventtoaheaderinGatsby【发布时间】:2021-05-1116:17:31【问题描述】:总结问题目标是在查看器向下滚动页面时更改标题/导航栏的样式。标题已经固定/固定到位,但是我希... 查看详情

相对布局搞砸了如何固定它的位置

】相对布局搞砸了如何固定它的位置【英文标题】:Relativelayoutmesseduphowfixeditsposition【发布时间】:2019-09-1504:04:42【问题描述】:您好朋友,我创建了具有文本和媒体控制器按钮的相对布局,当我开始播放歌曲时它弄乱了我的布... 查看详情

如何在 UITableView 中添加背景视频并在滚动 UITableViewCells 时使其固定?

】如何在UITableView中添加背景视频并在滚动UITableViewCells时使其固定?【英文标题】:HowtoaddabackgroundvideoinaUITableView&makeitfixedwhenscrollingthroughUITableViewCells?【发布时间】:2016-09-2614:23:06【问题描述】:当我将视频(AVPlayer)添加到UITa... 查看详情

在相对布局中不可见的视图

...图,Leftline和rightline不可见,而带有IDcardline的视图可见。如何使所有视图可见?<?xmlversion="1.0"encoding="ut 查看详情

如何在视图中居中滚动视图

】如何在视图中居中滚动视图【英文标题】:howtocenterthescrollviewinsidetheView【发布时间】:2020-02-1105:50:20【问题描述】:我在视图控制器的视图中添加了一个滚动视图。在iPhoneXR上,滚动视图子视图出现在左侧,因为滚动视图不展... 查看详情

如何在引导程序 3 中向下滚动带有固定标题(导航栏)的表格行时将表格标题(标题)粘贴在顶部?

】如何在引导程序3中向下滚动带有固定标题(导航栏)的表格行时将表格标题(标题)粘贴在顶部?【英文标题】:Howtosticktableheader(thead)ontopwhilescrollingdownthetablerowswithfixedheader(navbar)inbootstrap3?【发布时间】:2014-09-1011:33:05【问... 查看详情

如何制作比屏幕尺寸宽的表格,可滚动并保持标题行固定?

】如何制作比屏幕尺寸宽的表格,可滚动并保持标题行固定?【英文标题】:Howtomakeatable,whichiswiderthanscreensize,scrollableandkeepheaderrowfixed?【发布时间】:2011-02-0714:23:02【问题描述】:我有一个table,有2列,每列宽800像素。我想在800... 查看详情

如何在 ios 中使用自动布局更改滚动视图内容大小

】如何在ios中使用自动布局更改滚动视图内容大小【英文标题】:HowtochangescrollViewcontentsizesusingauto-layoutsinios【发布时间】:2015-10-2006:28:56【问题描述】:我在我的滚动视图上添加3个UITextfields和1个UIButton。我的主要要求是当我点... 查看详情

滚动视图内的Android约束布局高度无效

...的内容也有固定高度。滚动视图高度为300dp,直接子级(相对布局)为500dp,文本视图距顶部的距离为301dp。这意味着在我到达文本视图后,底部 查看详情

在 UITableView 中使用自动布局进行动态单元格布局和可变行高

...iablerowheights【发布时间】:2013-09-1116:48:39【问题描述】:如何在表格视图中使用UITableViewCells内的自动布局来让每个单元格的内容和子视图(自行/自动)确定行高,同时保持平滑的滚动性能?【问题讨论 查看详情