草庐IT

android - 中间需要一个页眉、页脚和 ScrollView 。当前代码不工作

coder 2023-12-29 原文

过去一个小时我一直在搜索这里和其他网站,试图找出我做错了什么。正如标题所示,我需要一个带按钮的页眉、一个 ScrollView ,然后是一个带按钮的页脚。我希望页眉和页脚始终可见。找到的所有内容都说要制作相对布局,将其与父级顶部对齐,创建页脚,将其与父级底部对齐,然后创建一个 ScrollView ,将其设置在页脚上方和页眉下方。出于某种原因,我的代码只是决定忽略它。

<RelativeLayout
    android:id="@+id/topBar_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_alignParentTop="true"
    android:background="@color/colorBackground">

    <Button
        android:id="@+id/charInfoBtn_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="General"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintStart_toStartOf="parent"/>

</RelativeLayout>

<ScrollView
    android:id="@+id/genLayoutScroll_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:layout_above="@id/bottomBar_id"
    android:layout_below="@id/topBar_id>

    <LinearLayout
      //bunch of junk that users scroll through
    </LinearLayout>

</ScrollView>

<RelativeLayout
    android:id="@+id/bottomBar_id"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    app:layout_constraintEnd_toEndOf="parent"
    app:layout_constraintBottom_toBottomOf="parent"
    android:background="@color/colorBackground">

    <Button
        android:id="@+id/genApplyBtn_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Apply"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintEnd_toEndOf="parent" />

</RelativeLayout>

将其用作我当前的代码, ScrollView 位于顶部栏和底部栏的顶部。

如果我删除 layout_above 和 layout_below 行,并将其替换为 app:layout_constraintBottom_toTopOf="@id/bottomBar_id"然后 ScrollView 不再越过我的底部栏,但现在顶部栏,并且 ScrollView 的顶部丢失了。

然后我将 app:layout_constraintTop_toBottomOf="@id/topBar_id"添加到 ScrollView ,它又回到了与 layout_below 和 layout_above 相同的状态。

我确定我在这里遗漏了什么,我只是无法弄清楚我遗漏了什么。希望有人能指出我犯的愚蠢错误。

附言我知道我的一些代码现在有点草率,主要是因为试图找出这个问题。

最佳答案

到目前为止,最简单的方法是使用垂直 LinearLayout作为 View 的根,并使用“布局权重”的概念使中间元素 (ScrollView) 填满屏幕。

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

    <Button
        android:id="@+id/charInfoBtn_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="General"/>

    <ScrollView
        android:id="@+id/genLayoutScroll_id"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!-- your contents here -->

    </ScrollView>

    <Button
        android:id="@+id/genApplyBtn_id"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Apply"/>

</LinearLayout>

如果您需要在每个栏中放置多个按钮,您可以将它们包裹在一个水平的LinearLayout 中。 .

这样做的原因是 android:layout_weight="1" <ScrollView> 上的属性标签。为单个 View 分配权重将使其占据所有剩余空间,在其他 View 获得它们需要的空间之后。所以你的按钮可以获得他们想要的尽可能多的空间,而 ScrollView 获得其余部分。由于它位于中间,这必然会将底部按钮向下推到屏幕的末尾。

关于android - 中间需要一个页眉、页脚和 ScrollView 。当前代码不工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47368427/

有关android - 中间需要一个页眉、页脚和 ScrollView 。当前代码不工作的更多相关文章

  1. ruby - 我需要将 Bundler 本身添加到 Gemfile 中吗? - 2

    当我使用Bundler时,是否需要在我的Gemfile中将其列为依赖项?毕竟,我的代码中有些地方需要它。例如,当我进行Bundler设置时:require"bundler/setup" 最佳答案 没有。您可以尝试,但首先您必须用鞋带将自己抬离地面。 关于ruby-我需要将Bundler本身添加到Gemfile中吗?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.com/questions/4758609/

  2. ruby-on-rails - 由于 "wkhtmltopdf",PDFKIT 显然无法正常工作 - 2

    我在从html页面生成PDF时遇到问题。我正在使用PDFkit。在安装它的过程中,我注意到我需要wkhtmltopdf。所以我也安装了它。我做了PDFkit的文档所说的一切......现在我在尝试加载PDF时遇到了这个错误。这里是错误:commandfailed:"/usr/local/bin/wkhtmltopdf""--margin-right""0.75in""--page-size""Letter""--margin-top""0.75in""--margin-bottom""0.75in""--encoding""UTF-8""--margin-left""0.75in""-

  3. ruby-on-rails - 'compass watch' 是如何工作的/它是如何与 rails 一起使用的 - 2

    我在我的项目目录中完成了compasscreate.和compassinitrails。几个问题:我已将我的.sass文件放在public/stylesheets中。这是放置它们的正确位置吗?当我运行compasswatch时,它不会自动编译这些.sass文件。我必须手动指定文件:compasswatchpublic/stylesheets/myfile.sass等。如何让它自动运行?文件ie.css、print.css和screen.css已放在stylesheets/compiled。如何在编译后不让它们重新出现的情况下删除它们?我自己编译的.sass文件编译成compiled/t

  4. ruby - 如何在 buildr 项目中使用 Ruby 代码? - 2

    如何在buildr项目中使用Ruby?我在很多不同的项目中使用过Ruby、JRuby、Java和Clojure。我目前正在使用我的标准Ruby开发一个模拟应用程序,我想尝试使用Clojure后端(我确实喜欢功能代码)以及JRubygui和测试套件。我还可以看到在未来的不同项目中使用Scala作为后端。我想我要为我的项目尝试一下buildr(http://buildr.apache.org/),但我注意到buildr似乎没有设置为在项目中使用JRuby代码本身!这看起来有点傻,因为该工具旨在统一通用的JVM语言并且是在ruby中构建的。除了将输出的jar包含在一个独特的、仅限ruby​​

  5. ruby - 使用 Vim Rails,您可以创建一个新的迁移文件并一次性打开它吗? - 2

    使用带有Rails插件的vim,您可以创建一个迁移文件,然后一次性打开该文件吗?textmate也可以这样吗? 最佳答案 你可以使用rails.vim然后做类似的事情::Rgeneratemigratonadd_foo_to_bar插件将打开迁移生成的文件,这正是您想要的。我不能代表textmate。 关于ruby-使用VimRails,您可以创建一个新的迁移文件并一次性打开它吗?,我们在StackOverflow上找到一个类似的问题: https://sta

  6. ruby-on-rails - Rails 源代码 : initialize hash in a weird way? - 2

    在rails源中:https://github.com/rails/rails/blob/master/activesupport/lib/active_support/lazy_load_hooks.rb可以看到以下内容@load_hooks=Hash.new{|h,k|h[k]=[]}在IRB中,它只是初始化一个空哈希。和做有什么区别@load_hooks=Hash.new 最佳答案 查看rubydocumentationforHashnew→new_hashclicktotogglesourcenew(obj)→new_has

  7. ruby-on-rails - Rails - 一个 View 中的多个模型 - 2

    我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何

  8. ruby-on-rails - 渲染另一个 Controller 的 View - 2

    我想要做的是有2个不同的Controller,client和test_client。客户端Controller已经构建,我想创建一个test_clientController,我可以使用它来玩弄客户端的UI并根据需要进行调整。我主要是想绕过我在客户端中内置的验证及其对加载数据的管理Controller的依赖。所以我希望test_clientController加载示例数据集,然后呈现客户端Controller的索引View,以便我可以调整客户端UI。就是这样。我在test_clients索引方法中试过这个:classTestClientdefindexrender:template=>

  9. ruby - 无法让 RSpec 工作—— 'require' : cannot load such file - 2

    我花了三天的时间用头撞墙,试图弄清楚为什么简单的“rake”不能通过我的规范文件。如果您遇到这种情况:任何文件夹路径中都不要有空格!。严重地。事实上,从现在开始,您命名的任何内容都没有空格。这是我的控制台输出:(在/Users/*****/Desktop/LearningRuby/learn_ruby)$rake/Users/*******/Desktop/LearningRuby/learn_ruby/00_hello/hello_spec.rb:116:in`require':cannotloadsuchfile--hello(LoadError) 最佳

  10. ruby - rspec 需要 .rspec 文件中的 spec_helper - 2

    我注意到像bundler这样的项目在每个specfile中执行requirespec_helper我还注意到rspec使用选项--require,它允许您在引导rspec时要求一个文件。您还可以将其添加到.rspec文件中,因此只要您运行不带参数的rspec就会添加它。使用上述方法有什么缺点可以解释为什么像bundler这样的项目选择在每个规范文件中都需要spec_helper吗? 最佳答案 我不在Bundler上工作,所以我不能直接谈论他们的做法。并非所有项目都checkin.rspec文件。原因是这个文件,通常按照当前的惯例,只

随机推荐