我在 CollapsingToolbarLayout 中有三个按钮。展开时,想法是修改正在显示的图片库上的过滤器,或者弹出一个编辑对话框。我得到的结果不一致——按钮只间歇性地响应点击。
最终,我意识到问题在于可点击区域比 View 的客户端矩形要小得多。在水平方向上,它们看起来很正常,但在垂直方向上,可点击区域比按钮短得多。在模拟器中,我能够相当精确地确定边界:
你可以正常地从左到右触摸它们,但从上到下是错误的。
我一直在尝试从文档、官方指南、在线教程和开源代码示例的各种 fragment 中拼凑出这个布局。我不完全理解所有奇特的支持/设计布局是如何协同工作的,或者所有配置属性在组合时究竟做了什么,所以修复很可能是对一两个属性的简单更改。这是我的布局:
<?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"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fitsSystemWindows="true"
tools:context=".activity.MainActivity">
<android.support.design.widget.AppBarLayout
android:id="@+id/appBarLayout"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:fitsSystemWindows="true"
android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar">
<android.support.design.widget.CollapsingToolbarLayout
android:id="@+id/collapsingToolbarLayout"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:minHeight="?android:actionBarSize"
app:layout_scrollFlags="scroll|exitUntilCollapsed|snap"
app:contentScrim="?attr/colorPrimary"
android:background="?attr/colorPrimary"
app:expandedTitleMarginEnd="64dp"
app:expandedTitleMarginStart="48dp"
android:theme="@style/Widget.Design.CollapsingToolbar">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:paddingTop="32dp"
android:paddingBottom="64dp"
android:fitsSystemWindows="true"
app:layout_collapseMode="none"
android:background="@android:color/transparent"
android:orientation="horizontal">
<ImageButton android:id="@+id/btnTags"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_tag"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
<ImageButton android:id="@+id/btnAlbums"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_albums"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
<ImageButton android:id="@+id/btnNewAlbum"
android:layout_width="64dp"
android:layout_height="64dp"
android:layout_weight="0.3"
android:src="@drawable/ic_new_album"
android:tint="?android:attr/buttonTint"
android:background="@drawable/ripple" />
</LinearLayout>
<android.support.v7.widget.Toolbar
android:id="@+id/toolbarMain"
android:layout_width="match_parent"
android:layout_height="?attr/actionBarSize"
app:layout_collapseMode="pin"
app:title="@string/app_name"
app:popupTheme="@style/ThemeOverlay.AppCompat.Light"
app:theme="@style/LouvreTheme.ToolbarStyle"/>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
<co.moonmonkeylabs.realmrecyclerview.RealmRecyclerView
android:id="@+id/recyclerAlbumGrid"
android:layout_width="match_parent"
android:layout_height="match_parent"
app:layout_behavior="@string/appbar_scrolling_view_behavior"
android:background="?android:attr/background"
app:rrvLayoutType="Grid"
app:rrvGridLayoutSpanCount="@integer/grid_span"
app:rrvIsRefreshable="false"
app:rrvSwipeToDelete="false" />
</android.support.design.widget.CoordinatorLayout>
然后,在我的 onViewCreated() 中,我为每个按钮分配了一个 OnClickListener。我可以可靠且可预测地触发它们,但只能通过单击上图所示的窄垂直带。
我已经尝试过的解决方法和调整:
ImageView 切换到 FloatingActionButton,最后是 ImageButtonandroid:fitsSystemWindows="true",包括所有wrap_content 更改为在它们显示的 VectorDrawable 中明确定义的尺寸LinearLayout 上的 android:minHeight 设置为与按钮相同的显式大小layout_weight 设置为 1.0,并将总和设置为 3.0LinearLayout 上以 paralax 和 none 的形式尝试 app:layout_collapseMode。我在 SO 上找到的唯一类似问题是:AppBarLayout and CollapsingToolbarLayout not able to contain Button?没有提供令人满意的答案,只是将按钮移到折叠区域之外的解决方法。
想法?
最佳答案
事实证明,工具栏 实际上在物理上保持在顶部,尽管看起来随着扩展的标题文本向下延伸。因此它部分覆盖了我按钮的前三分之二左右,我无法分辨,因为工具栏背景设置为透明。通过向工具栏添加对比色背景,发生的事情变得非常明显。
我发现并测试了两个简单的修复方法:
android:layout_marginTop="?android:actionBarSize" 添加到包含按钮的 LinearLayout 中,以便在 y 方向上将其绘制在工具栏下方。 关于android - 为什么我的按钮在 CollapsingToolbarLayout 中的点击区域太小?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39069549/
总的来说,我对ruby还比较陌生,我正在为我正在创建的对象编写一些rspec测试用例。许多测试用例都非常基础,我只是想确保正确填充和返回值。我想知道是否有办法使用循环结构来执行此操作。不必为我要测试的每个方法都设置一个assertEquals。例如:describeitem,"TestingtheItem"doit"willhaveanullvaluetostart"doitem=Item.new#HereIcoulddotheitem.name.shouldbe_nil#thenIcoulddoitem.category.shouldbe_nilendend但我想要一些方法来使用
类classAprivatedeffooputs:fooendpublicdefbarputs:barendprivatedefzimputs:zimendprotecteddefdibputs:dibendendA的实例a=A.new测试a.foorescueputs:faila.barrescueputs:faila.zimrescueputs:faila.dibrescueputs:faila.gazrescueputs:fail测试输出failbarfailfailfail.发送测试[:foo,:bar,:zim,:dib,:gaz].each{|m|a.send(m)resc
我试图在一个项目中使用rake,如果我把所有东西都放到Rakefile中,它会很大并且很难读取/找到东西,所以我试着将每个命名空间放在lib/rake中它自己的文件中,我添加了这个到我的rake文件的顶部:Dir['#{File.dirname(__FILE__)}/lib/rake/*.rake'].map{|f|requiref}它加载文件没问题,但没有任务。我现在只有一个.rake文件作为测试,名为“servers.rake”,它看起来像这样:namespace:serverdotask:testdoputs"test"endend所以当我运行rakeserver:testid时
作为我的Rails应用程序的一部分,我编写了一个小导入程序,它从我们的LDAP系统中吸取数据并将其塞入一个用户表中。不幸的是,与LDAP相关的代码在遍历我们的32K用户时泄漏了大量内存,我一直无法弄清楚如何解决这个问题。这个问题似乎在某种程度上与LDAP库有关,因为当我删除对LDAP内容的调用时,内存使用情况会很好地稳定下来。此外,不断增加的对象是Net::BER::BerIdentifiedString和Net::BER::BerIdentifiedArray,它们都是LDAP库的一部分。当我运行导入时,内存使用量最终达到超过1GB的峰值。如果问题存在,我需要找到一些方法来更正我的代
Rails2.3可以选择随时使用RouteSet#add_configuration_file添加更多路由。是否可以在Rails3项目中做同样的事情? 最佳答案 在config/application.rb中:config.paths.config.routes在Rails3.2(也可能是Rails3.1)中,使用:config.paths["config/routes"] 关于ruby-on-rails-Rails3中的多个路由文件,我们在StackOverflow上找到一个类似的问题
我有一个模型:classItem项目有一个属性“商店”基于存储的值,我希望Item对象对特定方法具有不同的行为。Rails中是否有针对此的通用设计模式?如果方法中没有大的if-else语句,这是如何干净利落地完成的? 最佳答案 通常通过Single-TableInheritance. 关于ruby-on-rails-Rails-子类化模型的设计模式是什么?,我们在StackOverflow上找到一个类似的问题: https://stackoverflow.co
我正在使用的第三方API的文档状态:"[O]urAPIonlyacceptspaddedBase64encodedstrings."什么是“填充的Base64编码字符串”以及如何在Ruby中生成它们。下面的代码是我第一次尝试创建转换为Base64的JSON格式数据。xa=Base64.encode64(a.to_json) 最佳答案 他们说的padding其实就是Base64本身的一部分。它是末尾的“=”和“==”。Base64将3个字节的数据包编码为4个编码字符。所以如果你的输入数据有长度n和n%3=1=>"=="末尾用于填充n%
我主要使用Ruby来执行此操作,但到目前为止我的攻击计划如下:使用gemsrdf、rdf-rdfa和rdf-microdata或mida来解析给定任何URI的数据。我认为最好映射到像schema.org这样的统一模式,例如使用这个yaml文件,它试图描述数据词汇表和opengraph到schema.org之间的转换:#SchemaXtoschema.orgconversion#data-vocabularyDV:name:namestreet-address:streetAddressregion:addressRegionlocality:addressLocalityphoto:i
我需要从一个View访问多个模型。以前,我的links_controller仅用于提供以不同方式排序的链接资源。现在我想包括一个部分(我假设)显示按分数排序的顶级用户(@users=User.all.sort_by(&:score))我知道我可以将此代码插入每个链接操作并从View访问它,但这似乎不是“ruby方式”,我将需要在不久的将来访问更多模型。这可能会变得很脏,是否有针对这种情况的任何技术?注意事项:我认为我的应用程序正朝着单一格式和动态页面内容的方向发展,本质上是一个典型的网络应用程序。我知道before_filter但考虑到我希望应用程序进入的方向,这似乎很麻烦。最终从任何
为什么4.1%2返回0.0999999999999996?但是4.2%2==0.2。 最佳答案 参见此处:WhatEveryProgrammerShouldKnowAboutFloating-PointArithmetic实数是无限的。计算机使用的位数有限(今天是32位、64位)。因此计算机进行的浮点运算不能代表所有的实数。0.1是这些数字之一。请注意,这不是与Ruby相关的问题,而是与所有编程语言相关的问题,因为它来自计算机表示实数的方式。 关于ruby-为什么4.1%2使用Ruby返