无法将视图放置在 RecyclerView 下方

2024-01-09

我无法放置Adview低于一个RecyclerView。目前RecyclerView占据了布局的其余部分并且Adview没有显示。我在网上找到的解决方案都没有解决我的问题。通常layout_weight or layout_below解决了问题,但在本例中并非如此。

XML

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    xmlns:ads="http://schemas.android.com/apk/res-auto"
    tools:context=".MainActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="#7c7c7c"
        android:focusable="true"
        android:focusableInTouchMode="true">


        <android.support.v7.widget.RecyclerView
            android:id="@+id/recycler_view"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/relContainer"
            android:background="@drawable/bordershadow2"
            android:paddingBottom="17dp"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="10dp" />


        <com.google.android.gms.ads.AdView
            android:id="@+id/adView"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_below="@+id/recycler_view"
            ads:adSize="BANNER"
            ads:adUnitId="ca-app-pub-3940256099942544/6300978111">
        </com.google.android.gms.ads.AdView>

        <RelativeLayout
            android:id="@+id/relContainer"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:background="@drawable/bordershadow"
            android:paddingLeft="@dimen/activity_horizontal_margin"
            android:paddingRight="@dimen/activity_horizontal_margin"
            android:paddingTop="@dimen/activity_vertical_margin">

           <TableLayout
                android:id="@+id/purchaseTableLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:paddingBottom="7dp"
                android:paddingTop="7dp"
                android:layout_alignParentTop="true"
                android:stretchColumns="0,1,2">

                <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:weightSum="3">

                    <TextView
                        android:id="@+id/textView1"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:paddingLeft="2dp"
                        android:singleLine="true"
                        android:textColor="#000"
                        android:textSize="24sp"
                        android:textStyle="bold" />

                    <TextView
                        android:id="@+id/textView2"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:paddingLeft="2dp"
                        android:singleLine="true"
                        android:textColor="#000"
                        android:textSize="24sp"
                        android:textStyle="bold" />

                    <Spinner
                        android:id="@+id/typeSpinner"
                        style="style/Theme.Material"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1"
                        android:gravity="center_vertical"
                        android:entries="@array/type_array"
                        android:textSize="@dimen/title_size" />
                </TableRow>
            </TableLayout>

            <EditText
                android:id="@+id/searchEditText"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:layout_centerHorizontal="true"
                android:layout_below="@+id/purchaseTableLayout"
                android:digits="abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ'() "
                android:hint="Search"
                android:imeOptions="actionDone"
                android:singleLine="true" />

            <TableLayout
                android:id="@+id/tableLayout"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:layout_below="@+id/searchEditText"
                android:paddingBottom="7dp"
                android:paddingTop="7dp"
                android:stretchColumns="0,1,2">

                <TableRow
                    android:layout_width="wrap_content"
                    android:layout_height="wrap_content"
                    android:weightSum="3.0">

                    <Spinner
                        android:id="@+id/sortRaceSpinner"
                        style="style/Theme.Material"
                        android:paddingTop="5dp"
                        android:paddingBottom="10dp"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1.0"
                        android:entries="@array/sort_race_array"
                        android:textSize="@dimen/title_size" />

                    <Spinner
                        android:id="@+id/sortAffinitySpinner"
                        style="style/Theme.Material"
                        android:paddingTop="5dp"
                        android:paddingBottom="10dp"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1.0"
                        android:entries="@array/sort_affinity_array"
                        android:textSize="@dimen/title_size" />

                    <Spinner
                        android:id="@+id/sortSpinner"
                        style="style/Theme.Material"
                        android:paddingTop="5dp"
                        android:paddingBottom="10dp"
                        android:layout_width="0dp"
                        android:layout_height="match_parent"
                        android:layout_weight="1.0"
                        android:entries="@array/sort_array"
                        android:textSize="@dimen/title_size" />
                </TableRow>
            </TableLayout>
        </RelativeLayout>
    </RelativeLayout>
</RelativeLayout>

我有一个视图需要位于具有动态大小的回收器视图下。 这意味着视图应该随着 RecyclerView 的增长而向下移动。

我的解决方案是将 paddingBottom 添加到 RecyclerView,然后将负 marginTop 添加到视图中,效果非常好。

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

    <android.support.v7.widget.RecyclerView
        android:paddingBottom="48dp"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        />

        <TextView
            android:layout_marginTop="-48dp"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            />
</LinearLayout>
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

无法将视图放置在 RecyclerView 下方 的相关文章

  • Android - 从资产中解析巨大(超大)JSON 文件的最佳方法

    我正在尝试从资产文件夹中解析一些巨大的 JSON 文件 我如何加载并添加到 RecyclerView 我想知道解析这种大文件 大约 6MB 的最佳方法是什么 以及您是否知道可以帮助我处理此文件的良好 API 我建议您使用GSON lib h
  • 如何在C#中从XML读取键值

    我有下面的 xml 格式文件 名为 ResourceData xml
  • 找不到 com.google.firebase:firebase-core:9.0.0 [重复]

    这个问题在这里已经有答案了 在遵循有些不一致的指示之后here https firebase google com docs admob android quick start name your project and here http
  • Android 中 Kotlin 协程的正确使用方式

    我正在尝试使用异步更新适配器内的列表 我可以看到有太多的样板 这是使用 Kotlin 协程的正确方法吗 这个可以进一步优化吗 fun loadListOfMediaInAsync async CommonPool try Long runn
  • 使用 Android 发送 HTTP Post 请求

    我一直在尝试从 SO 和其他网站上的大量示例中学习 但我无法弄清楚为什么我编写的示例不起作用 我正在构建一个小型概念验证应用程序 它可以识别语音并将其 文本 作为 POST 请求发送到 node js 服务器 我已确认语音识别有效 并且服务
  • 使用非 ASCII(自然语言)XML 标签是否合适?

    使用以非 ASCII 自然语言编写的 XML 标签 元素名称 是否合适 XML 规范允许这样做 请参阅Names http www w3 org TR 2006 REC xml11 20060816 NT Name and 例外情况 htt
  • 带有 EditText 和 Spinner 的对话框

    我有一个按钮 单击后会弹出一个对话框 我希望对话框有一个EditText and a Spinner对话框内 我不知道如何设置它的视图 我有一个代码AlertDialog它有效 只是EditText and Spinner我需要将其放入其中
  • 是否有 ADB 命令来检查媒体是否正在播放

    我想使用 ADB 命令检查根植于终端的外部设备中是否正在播放音频 视频 我无法找到任何 ADB 命令 如果有 我尝试过 adb shell dumpsys media player 我想要一个命令来指定视频是否正在运行 您可以使用以下命令查
  • 带有嵌套表的 XSLT 中的数据对齐问题

    我正在通过 FoundationPHP 使用 XSLT 和嵌套表生成 Word 文档 我想要的结果是 Table 1 Table 2 Image 1 Image 2 Label 1 Label 2 Data 1 Data 2 Table 3
  • JavaMail 只获取新邮件

    我想知道是否有一种方法可以在javamail中只获取新消息 例如 在初始加载时 获取收件箱中的所有消息并存储它们 然后 每当应用程序再次加载时 仅获取新消息 而不是再次重新加载它们 javamail 可以做到这一点吗 它是如何工作的 一些背
  • Google 云端硬盘身份验证异常 - 需要许可吗? (v2)

    我一直在尝试将 Google Drive v2 添加到我的 Android 应用程序中 但无法获得授权 我收到 UserRecoverableAuthIOException 并显示消息 NeedPermission 我感觉 Google A
  • 为什么 XML 中的 CDATA 语法看起来如此奇怪?

    CDATA 在 XML 中的使用如下
  • 在两个活动之间传输数据[重复]

    这个问题在这里已经有答案了 我正在尝试在两个不同的活动之间发送和接收数据 我在这个网站上看到了一些其他问题 但没有任何问题涉及保留头等舱的状态 例如 如果我想从 A 类发送一个整数 X 到 B 类 然后对整数 X 进行一些操作 然后将其发送
  • Android Studio - Windows 7 上的 Android SDK 问题

    我对 Google i o 2013 上发布的最新开发工具 Android Studio 有疑问 我已经成功安装了该程序并且能够正常启动 我可以导入现有项目并对其进行编辑 但是 当我尝试单击 SDK 管理器图标或 AVD 管理器图标时 或者
  • 我的设备突然没有显示在“Android 设备选择器”中

    我正在使用我的三星 Galaxy3 设备来测试过去两个月的应用程序 它运行良好 但从今天早上开始 当我将设备连接到系统时 它突然没有显示在 Android 设备选择器 窗口中 我检查过 USB 调试模式仅在我的设备中处于选中状态 谁能猜出问
  • Android 中麦克风的后台访问

    是否可以通过 Android 手机上的后台应用程序 服务 持续监控麦克风 我想做的一些想法 不断聆听背景中的声音信号 收到 有趣的 音频信号后 执行一些网络操作 如果前台应用程序需要的话 后台应用程序必须能够智能地放弃对麦克风的访问 除非可
  • 如何根据 gradle 风格设置变量

    我想传递一个变量test我为每种风格设置了不同的值作为 NDK 的定义 但出于某种原因 他总是忽略了最后味道的价值 这是 build gradle apply plugin com android library def test andr
  • 如何锁定/密码保护 XML 文件?

    我在 XML 文件中读取和写入数据 我不希望其他人阅读该文件 所以我想为我的文件创建密码或锁定文件 我怎样才能做到这一点 如果不使用加密软件 则无法使用密码保护 XML 文件 XML 文件只是文本 但像 PGP 谷歌搜索 这样的程序应该可以
  • 使用 xpath 和 vtd-xml 以字符串形式获取元素的子节点和文本

    这是我的 XML 的一部分
  • 强制 Listview 不重复使用视图(复选框)

    我做了一个定制Listview 没有覆盖getView 方法 Listview 中的每个项目都具有以下布局 联系布局 xml

随机推荐

  • 创建新DataFrame的性能

    我很惊讶timings创建 DataFrames 的这个问题 https stackoverflow com q 41861846 2901002 30000 rows x 2 columns df pd concat pd DataFra
  • 在 Lance Game 中向各个玩家发送“秘密”数据

    我想知道 lance gg 中是否有一种简单的方法可以仅向每个玩家发送特定于玩家的数据 而不是向所有玩家发送所有数据 我希望创建一个扑克游戏 并且不希望每个玩家持有的数据向所有玩家广播 而是只让每个玩家接收有关他们自己的牌的信息 这在当前的
  • 使用 CTE 有哪些优点/缺点?

    我正在考虑提高某些 SQL 的性能 目前 CTE 在脚本中被多次使用和引用 使用表变量我会得到改进吗 不能使用临时表 因为代码位于函数内 您确实必须进行性能测试 没有是 否的答案 根据上面 Andy Living 的帖子链接 CTE 只是查
  • RESTful认证API设计

    我有一个关于 RESTful API 设计的问题 遵循 REST 的准则 所有端点都应该是名词并且是复数形式 并且永远不应该是动词 但是 通常将身份验证路由设置为 login logout 两者都是动词 如果您应该遵守指南 这些路线应该看起
  • JProfiler 错误:IDE 无法找到所选类

    我在 J Profiler 中遇到问题 当我单击 查看源代码 时 出现一些错误 提示 IDE 无法找到所选类并且无法查看源代码 编辑会话设置 选择 应用程序设置 选项卡 选择 Java 文件路径 部分中的 源路径 单选按钮 然后在其中添加源
  • MySQL子查询中的用户变量

    Query Output gt SELECT foo 1 foo SELECT foo SELECT foo FROM SELECT foo AS foo subselect foo 1 foo SELECT foo SELECT foo
  • Vue.js 将 items 中的 item 作为 prop 传递给组件:我会修改 prop 吗?

    Vue js 新手 从文档中 一个简单的示例是使用组件呈现列表中的每一项 如下所示
  • 如何在 tkinter python gui 中查找鼠标点击附近的标签

    我如何识别鼠标点击附近的标签 这里我的定义 识别 应该识别非常接近鼠标点击的标签 from Tkinter import root Tk f Frame root f grid w Canvas f line1 w create line
  • git-svn dcommiting 单个 git 提交

    给定多个未推送git承诺 是否有可能git svn dcommit只有其中一项提交 例如我已经提交了 foo bar 和 baz 但现在我只想让 bar 最终出现在 svn 存储库中 这可能吗 以下假设您的工作正在进行master 首先 重
  • 构建ndk库出错

    我有一个带有本机部分的 Android 项目 现在我试图让 eclipse 编译所有东西 但在本机编译期间它给了我这个错误 sh ndk build all ERROR You are using a non Cygwin compatib
  • 删除数据库文件和 sqllocaldb 后,底层提供程序在打开时失败

    我正在调查我的经历问题在这里 https stackoverflow com questions 13001441 delete mdf file from app data causes exception cannot attach t
  • 如何使用列表视图的 onitemclicklistener 更改仅选定列表视图行的布局

    我需要创建ListView like Samsung Contact List 我需要显示该行的自定义布局 而该行是swiped 并且还需要在该行的背景中显示联系方式 请给我一些想法或参考 谢谢 list setOnItemClickLis
  • 使用 CSS 进行水平对齐

    我有以下代码 div class one p Test p p span style color Green span p div 我认为这是一个非常简单的问题 但我不懂CSS 如何使段落在中心水平对齐 这里有两个问题 将包含该段落的 DI
  • 使用 asp.net 和 iis 在 geoserver 中进行身份验证

    我不知道这是否是一个愚蠢的问题 但是如何将 asp net 身份验证与 openlayers 结合 我创建了一个登录页面来在 openlayers 中进行身份验证 在 c 中 服务器端 这是我的代码 Uri uri new Uri http
  • 防止缓存单个js文件

    我的资产目录中有一个 js erb 文件 这会读取一些特定于区域设置的配置 但是 当底层配置更改时 新文件不会提供给我的浏览器 我得到 304 未修改 如果我通过添加空格来更改 js erb 文件 则新文件将正确提供 每次添加配置时都这样做
  • Laravel 队列工作者与 cron

    我试图让我的网站在每次有人新注册时发送确认电子邮件 我在阅读完相关内容后按照下面的方式做了 但我仍然不相信这是最好的方法 在我的 cron 中每分钟运行并调用php artisan schedule run 在我的控制台 内核中 prote
  • 在 Vue 中显示基于 prop 的条件文本的其他方式?

    我有一个根据用户成员资格状态呈现文本的组件 我想根据该 prop 值更改插值文本 除了一堆 div p 标签之外 是否有更有效的方法来根据 prop 显示不同的文本v if or v show 不断有一堆堆叠的 div 只是大量的文本 任何
  • AngularJS - 使用 ENTER 键接受 ui.bootstrap 模式

    问题 我无法使用 ENTER 键接受模态窗口 我已经修改了默认的 Plunker 来向您展示我从现在开始所做的事情 gt Here http plnkr co edit 8OeJyEOBxm7B2aVHMyQ6 p preview 我拥有的
  • Discord.js 禁用“交互失败”

    如果交互 例如点击按钮 没有得到回复 discord 会在客户端显示 交互失败 他们希望你做什么 inter reply stuff 我想做的事 inter channel send stuff 这不是一个错误 我只是想防止出现 交互失败
  • 无法将视图放置在 RecyclerView 下方

    我无法放置Adview低于一个RecyclerView 目前RecyclerView占据了布局的其余部分并且Adview没有显示 我在网上找到的解决方案都没有解决我的问题 通常layout weight or layout below解决了