草庐IT

Android widget AppBarLayout 总是排在最前面

coder 2023-11-26 原文

您好,我正在开发小型 Android 应用程序,我试图在其中使用 AppBarLayout 显示工具栏。我想在我的工具栏顶部显示一些 View 。我尝试了以下方式:

<?xml version="1.0" encoding="utf-8"?>
<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"
    tools:context="com.example.nileshkashid.samplesearchbarapplication.Main2Activity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/toolbar_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        >
        <android.support.v7.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@android:color/transparent"
            />

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

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="150dp"
        android:background="@android:color/holo_red_dark"
        ></RelativeLayout>

    <RelativeLayout
        android:layout_width="150dp"
        android:layout_height="150dp"
        android:background="@android:color/holo_green_dark"
        ></RelativeLayout>


</RelativeLayout>

所以在上面的布局中,稍后两个相关布局都在我的 AppBarLayout 下。但我想在我的 toolbar_view 之上显示它们。我错过了什么或做错了什么。需要一些帮助。谢谢。

最佳答案

我真的对这个解决方案不满意,但到目前为止我发现了这个: 尝试将 android:elevation="5dp" 添加到 AppBarLayout 下方的 RelativeLayout:

<RelativeLayout
    android:layout_width="match_parent"
    android:layout_height="150dp"
    android:elevation="5dp"
    android:background="@android:color/holo_red_dark" />

我也遇到了这个问题,所以我会尝试对此进行更多调查。 (对我来说魔法值是5dp,不要问为什么。)

或者,您可以将 View 放在 AppBarLayout 中:

<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"    tools:context="com.example.nileshkashid.samplesearchbarapplication.Main2Activity">

    <android.support.design.widget.AppBarLayout
        android:id="@+id/toolbar_view"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <!-- You have to use a RelativeLayout here, because AppBarLayout is a LinearLayout. -->
        <RelativeLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content">

            <android.support.v7.widget.Toolbar
                android:id="@+id/toolbar"
                android:layout_width="match_parent"
                android:layout_height="?attr/actionBarSize"
                android:background="@android:color/transparent" />

            <RelativeLayout
                android:layout_width="match_parent"
                android:layout_height="150dp"
                android:background="@android:color/holo_red_dark" />

        </RelativeLayout>

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

    ....

</RelativeLayout>

关于Android widget AppBarLayout 总是排在最前面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35379214/

有关Android widget AppBarLayout 总是排在最前面的更多相关文章

  1. ruby-on-rails - Rails - 乐观锁定总是触发 StaleObjectError 异常 - 2

    我正在学习Rails,并阅读了关于乐观锁的内容。我已将类型为integer的lock_version列添加到我的articles表中。但现在每当我第一次尝试更新记录时,我都会收到StaleObjectError异常。这是我的迁移:classAddLockVersionToArticle当我尝试通过Rails控制台更新文章时:article=Article.first=>#我这样做:article.title="newtitle"article.save我明白了:(0.3ms)begintransaction(0.3ms)UPDATE"articles"SET"title"='dwdwd

  2. ruby - 字符串文字前面的 * 在 ruby​​ 中有什么作用? - 2

    这段代码似乎创建了一个范围从a到z的数组,但我不明白*的作用。有人可以解释一下吗?[*"a".."z"] 最佳答案 它叫做splatoperator.SplattinganLvalueAmaximumofonelvaluemaybesplattedinwhichcaseitisassignedanArrayconsistingoftheremainingrvaluesthatlackcorrespondinglvalues.Iftherightmostlvalueissplattedthenitconsumesallrvaluesw

  3. ruby - Ruby 导入的方法总是私有(private)的吗? - 2

    最好用一个例子来解释:文件1.rb:deffooputs123end文件2.rb:classArequire'file1'endA.new.foo将给出错误“':调用了私有(private)方法'foo'”。我可以通过执行A.new.send("foo")来解决这个问题,但是有没有办法公开导入的方法?编辑:澄清一下,我没有混淆include和require。另外,我不能使用正常包含的原因(正如许多人正确指出的那样)是因为这是元编程设置的一部分。我需要允许用户在运行时添加功能;例如,他可以说“run-this-app--includefile1.rb”,应用程序的行为将根据他在file1

  4. ruby-on-rails - 为什么 do/end 和 {} 不总是等价的? - 2

    这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:RubyblockandunparenthesizedargumentsWhatisthedifferenceorvalueoftheseblockcodingstylesinRuby?我一直认为以下只是同一件事的两种表达方式:[1,2,3].collect{|i|i*2}[1,2,3].collectdo|i|i*2end但是我在我的一个ERB模板中发现了一些奇怪的行为,这两种语法似乎在做两件不同的事情。这段代码效果很好:m))}}%>但是当我将其重写为:m))endend%>...我最终得到了我的@men

  5. ruby - Ruby 中的 "=="是否总是值相等? - 2

    抱歉,如果重复(我没找到)这只是为了确认Ruby的运算符==始终执行相等比较。IE。a==b将a的值与b的值进行比较,而不是像Java那样比较它们是否指向内存中的同一个对象(对于后者,在Ruby中,您应该使用a.object_id==b.object_id).因此,在Ruby中将字符串值与==进行比较是安全的(而在Java中这样做并不安全)谢谢编辑:问题在于任何Ruby对象的默认==行为,因为它会误导Java-C-C++程序员假设a==b比较引用本身,而不是引用内容。无论如何,你可以检查这段代码,使用字符串one="hello"two="he"two编辑2。所以,在Ruby中,比较a=

  6. ruby-on-rails - Rails 4 测试用户初始化总是空白 - 2

    嘿,我有一个看起来像这样的测试test'createaccount'doifUser.create(email:'me@test.com',password:'blahblah')asserttrueelseassertUser.msgendend但是当我尝试运行它时,我收到如下错误消息:1)Error:UserTest#test_create_account:ActiveRecord::RecordNotUnique:PG::UniqueViolation:ERROR:duplicatekeyvalueviolatesuniqueconstraint"index_users_on_e

  7. ruby-on-rails - Ruby On Rails 自定义路由总是重定向到 Controller 的显示操作 - 2

    我正在尝试创建一条新路线,以便我可以利用RoR的路径变量功能,即new_game_path。就我而言,我想使用load_game_path我已经为适当的Controller创建了一个Action,目前路由如下:resources:gamesdoget'load',on::collectionend每次我使用load_games_path它都使用正确的URI,但似乎重定向到GamesController的显示操作并显示游戏的继承显示View。我检查了rakeroutes,我看到我新创建的路线似乎是所需的路径/games/load(文件路径:/views/games/load.html.e

  8. ruby-on-rails - 使用 spork 的 Rails 项目 - 总是必须使用 spork? - 2

    如果我在我的rails项目中使用spork并且有一个像这样的spec_helper.rb文件require'spork'Spork.preforkdo...endSpork.each_rundo...end这是否意味着当我通过rspecspec运行我的规范时,我需要始终让spork运行?意思是,如果我还没有在终端窗口中执行$spork,是否意味着我的规范将无法正常运行? 最佳答案 没有。我们的spechelper中有spork,但我们不会经常使用它,因为它会减慢大型套件的整体测试速度。我们仅在快速迭代时运行spork,在TDD期间重

  9. ruby - 枚举器 `Array#each` 's {block} can' t 总是更改数组值? - 2

    好吧,也许这很简单,但是......鉴于此:arr=("a".."z").to_aarr=>["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]..我正在尝试将所有“arr”值更改为“bad”为什么这行不通?arr.each{|v|v="bad"}arr=>["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v"

  10. ruby-on-rails - 日志 rails 控制台总是在生产环境中归档 - 2

    您可能自己知道,有时您必须通过Rails控制台在实时生产机器上执行任务...我通常这样开始:bundleexecrailsconsole-eproduction但由于它是生产机器,我想将Rails控制台的所有输入和输出记录到一个文件中,例如到/home/sshuser/myproject/console_sessions/2016_09_09__14_33_33.txt有人知道怎么做吗?我想自动启动记录器,但前提是我运行控制台?(我正在运行Rails3.2)谢谢! 最佳答案 这是一个解决方案,整个系统只有一个文件,不修改Rails项

随机推荐