草庐IT

android - View Pager 的 fragment 隐藏在 Tab Bar 后面

coder 2023-11-20 原文

我的 android 项目中的标签栏和 ViewPager 有问题。该应用程序的作用它有一个 Activity ,该 Activity 承载一个选项卡布局,然后有 2 个 fragment 代表每个选项卡。

当 Activity 打开时,它会发送到 API 以获取一些数据,并将数据放入每个 fragment 中的 Recycler View 和 Card 布局的数据适配器中。

回收器 View 将包含 3 个项目,但仅显示 2 个,因为第一个隐藏在工具栏和/或选项卡栏下,如下面的屏幕截图所示。

下面是我的activity的布局文件

<?xml version="1.0" encoding="utf-8"?>
<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.BoardiesITSolution.CritiMonApp.AppsActivity">

    <android.support.design.widget.AppBarLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
        <include layout="@layout/toolbar" />
        <android.support.design.widget.TabLayout
            android:id="@+id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            app:tabMode="fixed"
            app:tabGravity="fill" />
    </android.support.design.widget.AppBarLayout>

    <android.support.v4.view.ViewPager
        android:id="@+id/viewpager"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />
        <!--app:layout_behaviour="@string/appbar_scrolling_view_behaviour" />-->
</android.support.design.widget.CoordinatorLayout>

下面是 fragment 的布局

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <view
        android:id="@+id/recycler_view"
        class="android.support.v7.widget.RecyclerView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_centerInParent="true" />
</LinearLayout>

下面是卡片布局的布局

<android.support.v7.widget.CardView xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:cardview="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="80dp"
    android:layout_margin="8dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="80dp"
        android:elevation="5dp">
        <TextView
            android:id="@+id/txtApplicationName"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_centerVertical="true"
            android:maxLines="3"
            android:padding="8dp"
            android:textColor="#222"
            android:textSize="15dp"
            android:layout_centerInParent="true"/>

    </RelativeLayout>
</android.support.v7.widget.CardView>

下面是上面提到的显示问题的屏幕截图。我对一些文本进行了像素化处理,但它应该是我的意思,应该有 3 个项目,但第一个项目隐藏在选项卡栏下方。

最佳答案

编辑:正如下面@smeet 和@hardik 所建议的那样,添加滚动行为 app:layout_behavior="@string/appbar_scrolling_view_behavior" 应该可以解决问题,同时保留滚动行为。 只有当 View 是协调器布局的直接 subview 时,滚动行为才有效。


旧答案

只需将您的 appbar 布局和 viewpager 包装在垂直的 LinearLayout 中

<android.support.design.widget.CoordinatorLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    tools:context="com.BoardiesITSolution.CritiMonApp.AppsActivity">

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

        //appbar layout

        //viewpager    


    </LinearLayout>

</android.support.design.widget.CoordinatorLayout>

根据文档,CoordinatorLayout 是一个功能强大的 FrameLayout。因此,您可以期待典型的“将 View 置于其他 View 之上”的 FrameLayout 行为。

关于android - View Pager 的 fragment 隐藏在 Tab Bar 后面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33319928/

有关android - View Pager 的 fragment 隐藏在 Tab Bar 后面的更多相关文章

  1. 安卓apk修改(Android反编译apk) - 2

    最近因为项目需要,需要将Android手机系统自带的某个系统软件反编译并更改里面某个资源,并重新打包,签名生成新的自定义的apk,下面我来介绍一下我的实现过程。APK修改,分为以下几步:反编译解包,修改,重打包,修改签名等步骤。安卓apk修改准备工作1.系统配置好JavaJDK环境变量2.需要root权限的手机(针对系统自带apk,其他软件免root)3.Auto-Sign签名工具4.apktool工具安卓apk修改开始反编译本文拿Android系统里面的Settings.apk做demo,具体如何将apk获取出来在此就不过多介绍了,直接进入主题:按键win+R输入cmd,打开命令窗口,并将路

  2. Ruby隐藏与覆盖 - 2

    我刚刚了解到,在Java中,覆盖和隐藏之间是有区别的(静态方法是隐藏的,而不是覆盖),这意味着Java使用早期绑定(bind)和后期绑定(bind)。是否有与方法隐藏类似的东西,或者它只是具有方法重写? 最佳答案 Java具有三种不同的“方法”:实例方法,静态方法和构造函数。Ruby只有一个:实例方法。在Java中,静态方法的行为必须不同于实例方法,因为类不是对象。它们没有类,因此也没有父类(superclass),因此没有要覆盖的内容。在Ruby中,类与其他任何对象一样都是对象,它们具有一个类,该类可以具有父类(superclas

  3. iNFTnews | 周杰伦18年前未发布的作品Demo,藏在了区块链技术里 - 2

    当音乐碰上区块链技术,会擦出怎样的火花?或许周杰伦已经给了我们答案。8月29日下午,B站独家首发周杰伦限定珍藏Demo独家访谈VCR,周杰伦在VCR里分享了《晴天》《青花瓷》《搁浅》《爱在西元前》四首经典歌曲Demo背后的创作故事,并首次公布18年前未发布的神秘作品《纽约地铁》的Demo。在VCR中,方文山和杰威尔音乐提及到“多亏了区块链技术,现在我们可以将这些Demos,变成独一无二具有收藏价值的艺术品,这些Demos可以在薄盒(国内数藏平台)上听到。”如何将音乐与区块链技术相结合,薄盒方面称:“薄盒作为区块链技术服务方,打破传统对于区块链技术只能作为数字收藏的理解。聚焦于区块链技术赋能,在

  4. ruby-on-rails - Rails 4 真实性 token - 在 header 和表单隐藏输入中? - 2

    我正试图在Rails中获得完整的页面缓存,但我在CSRF方面遇到了很大的障碍——或者可能只是我对它的理解。我目前有form_authenticity_token存储在cookie中的字符串,JS可以使用该cookie访问和重写header标签。我在生成的HTML中有两个地方可以找到标记:1)在头部2)在表单的隐藏输入元素中如前所述,这些哈希值彼此不同(在未启用缓存的开发模式下)。他们为什么不同?为什么我可以删除headmeta标签并保留表单输入并且允许请求​​?然而,当我删除表单输入标签并保留标题时,请求被拒绝了吗?实际上这意味着head标签是无用的,不是吗?我可以将表单输入标签重写为

  5. 驱动开发:内核无痕隐藏自身分析 - 2

    在笔者前面有一篇文章《驱动开发:断链隐藏驱动程序自身》通过摘除驱动的链表实现了断链隐藏自身的目的,但此方法恢复时会触发PG会蓝屏,偶然间在网上找到了一个作者介绍的一种方法,觉得有必要详细分析一下他是如何实现的进程隐藏的,总体来说作者的思路是最终寻找到MiProcessLoaderEntry的入口地址,该函数的作用是将驱动信息加入链表和移除链表,运用这个函数即可动态处理驱动的添加和移除问题。MiProcessLoaderEntry(pDriverObject->DriverSection,1)添加MiProcessLoaderEntry(pDriverObject->DriverSection,

  6. ruby-on-rails - 在 Ruby on Rails 中隐藏字段 - 2

    我的数据库中有一个名为IP的字段,当他在我的Rails内置博客中发送消息时,我将用户IP(在#create方法中)放在该字段中。但是当我想以另一种格式(JSON)查看文章时,该字段是可见的。如何隐藏字段IP? 最佳答案 您可以在Controller中的格式block中执行此操作,如下所示:respond_todo|format|format.json{render:json=>@user,:except=>[:ip]}#orwithoutformatblock:@user.to_json(:except=>:ip)end如果你想普遍

  7. ruby - 为什么 Gosu 隐藏我的鼠标指针? - 2

    我正在使用Gosugem进行一些图形编程。问题是,当我创建一个窗口时,我的鼠标指针被隐藏了。我可以猜到鼠标在某个时刻的位置,我可以凭直觉点击,但我的用户可能不会。如何显示指针? 最佳答案 如果你想使用系统光标你可以这样做classWindow查看libgosu的文档RubyGosurdocReference/Window 关于ruby-为什么Gosu隐藏我的鼠标指针?,我们在StackOverflow上找到一个类似的问题: https://stackoverf

  8. ruby-on-rails - 如何使用私有(private)提交隐藏提要? - 2

    在评估表单中有一个提交按钮和一个按钮。如果点击私有(private)提交,提交的信息将对查看个人资料的其他用户隐藏。我们怎样才能同时使用隐藏提交的信息以防止在提要上显示?activities/index.html.erbFeed#We'dneedtomake.public_valuationsworkwiththiswithoutgettinganundefinedmethoderror.activities_controller.rbclassActivitiesController为简洁起见,我将只包含_create(还有update和destroy)。每次用户提交估价时,它都会在

  9. ruby - 如何在 rails_admin 的编辑表单中隐藏 "Save and Add Another"按钮? - 2

    我在我的Rails应用程序中应用了rails_admingem。我想删除特定模型编辑表单中一些不必要的按钮,并添加我自己的自定义按钮。请查看屏幕截图,了解我要删除的内容。 最佳答案 @montells复制https://github.com/sferik/rails_admin/blob/master/app/views/rails_admin/main/_submit_buttons.html.haml这个页面在你的repo中,位于“views/rails_admin/main/_submit_buttons.html.haml”

  10. ruby - 从企业防火墙后面安装 gem - 2

    我怀疑公司防火墙阻止安装gem。我定义了HTTP_PROXY,我可以通过以下命令查看远程gem:jruby-Sgemlist-r但是当我去安装gem时,我得到一个404:jruby-Sgeminstallrails除了维护内部gem存储库之外,是否有解决此问题的良好解决方法? 最佳答案 对于ruby​​gems,将它放在我的gem.bat中这对我有用@"%~dp0ruby.exe""%~dpn0"%*--http-proxyhttp://domainname.ccc.com:8080对于jrubygems这有效@"%~dp0jrub

随机推荐