- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
正如标题所说,我在 MenuItem
上使用 setActionView
进行设置,布局如下:
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ProgressBar
android:layout_width="32dp"
android:layout_height="32dp"
android:layout_margin="4dp"
android:layout_centerInParent="true"/>
</RelativeLayout>
问题是 ProgressBar
显示为右对齐。 (它应该与中心对齐,与 MenuItem
图标相同。图标为 32dp
我怎样才能做到这一点?
最佳答案
我今天遇到了类似的问题,但在 SO 上找不到任何好的 QA。因此我做了一些研究。以下是我对此事的调查结果:
Android Menu is implemented in this way:
如果您将 actionView 膨胀为:
并且您不设置图标,将标题设置为“”并设置 actionView 以使 menuItem 看起来仅包含您使用 setActionView 扩充的自定义 View ,然后:
Android forces the custom view's width to be wrap_content and remaining area gets occupied by icon+title of the menuItem.
我们可以将此实现视为:
将 margin 之后的整个 View 想象成 ParentLinearLayout,它分为 LinearLayout1 和 LinearLayout2(上图中描述为 Layout 1 和布局2分别)
现在 LinearLayout1 有 width=0dp 和 weight=1而 LinearLayout2 有 width=wrap_content
因此无论我们设置什么,目前我们都无法在菜单中右对齐膨胀的自定义 View (action view)。
To be technically accurate, you can right align if you really need this done by checking out the internal implementation code for the navigation menu by Android. But not really worth the effort. Any feature is a tradeoff of time required vs outcome.
关于android - MenuItem actionView 右对齐,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22866378/
C:\Users\Clarion Smith\Documents\Sites\simple_cms>rails server C:/Ruby22/lib/ruby/gems/2.2.0/gems/ac
我有一个基本的静态网页。 class StaticPagesController true %> 这是显示为导致错误的行。导致问题的原因是什么? 当我删除 stylesheet_link_tag
我有一个具有以下命名空间的 ruby View :ActionView::Base.new 但我想添加一个新方法以供此 ActionView::Base 类使用。 最佳答案 在 myapp/lib
所以我实现了为我的 ActionBar 中的 MenuItem 设置自定义 ActionView,太棒了! 现在,如何让 menuItem 显示它的标题(在 xml 中设置)? 这很重要,因为我希望用
将 mysite 部署到 VPS 后,我面临此运行时错误。请注意,在我的本地机器上,一切正常。 当我尝试通过 Controller 路由访问任何 View 时,可以说 PostsController#
我在 Rails 中遇到一些路由问题。 我已经为 Project 模型准备了一个模型,所以我使用 rails generate scaffold_controller 生成了一些默认 Controll
正如标题所说,我在 MenuItem 上使用 setActionView 进行设置,布局如下: 问题是 ProgressBar 显示为右对齐。 (它应该与中心对齐,与 MenuItem
我在 application_contoller.rb 中有一个方法,其中包含对 send_file 的调用。我从 javascript 渲染的部分调用它,并收到以下错误 - ActionView::
运行下面的代码时出现以下异常: uninitialized constant ActionView::CompiledTemplates::Current Controller : class Use
当 Google 机器人尝试访问我的某个 Controller 时,我收到此错误消息。 ActionView::MissingTemplate: Missing template channels/s
我正在测试 Rails Controller 并尝试使用代码执行获取: delete :remove_logs, :id => 3 它始终返回一个 ActionView::MissingTemplat
在将我的元素推送到 Amazon Web Services 上的实时环境然后访问该域时,我目前遇到了一个错误。 ActionView::Template::Error (Command 'java -
我已经安装了 timezone gem 并且在我看来 现在我得到了 uninitialized constant ActionView::CompiledTemplates::Timezone 还有
我想在我的操作栏中创建一个始终展开的搜索窗口。我正在使用 ActionBar Sherlock 库。根据我发现的一些样本,这段代码应该可以解决问题 public boolean onCreat
我在抽屉导航中使用支持的 NavigationView 来显示项目菜单。 我想在菜单项旁边显示连接请求计数器。 我试过像这样在 XML 菜单定义中设置 actionLayout ..
现在,我不得不承认,我是 Ruby on Rails 的新手,并不是很了解每个概念。我已经安装了 Devise 进行身份验证并遵循了 this guide在我的 View 中包含注册和登录链接。 这是
我一直在苦苦寻找这个问题的答案,显然我还没有做到。我尝试编码我的第一个小部分,我可以毫无问题地打开服务器,但是当我打开它时,服务器没有向我展示我编码的内容,而是告诉我:类型错误:对象不支持此属性或方法
我正在使用 Rails 3.2.3/Ruby 1.9.3p125/jbuilder (0.4.0) 在我的 view/mycontroller 文件夹中,我有一个 show.json.jbuilder
我已经使用 capistrano 部署了我的应用程序在 AWS , 与 nginx和 unicorn .当我打开我的主页时,它是空的。这是我的unicorn日志 Started GET "/" for
我正在使用 ruby on rails 3。我有一个名为 Content 的模型.在 Controller 中,我提取了一些变量并将它们传递给查看器。在查看器中,我想使用我自制的函数,这样我就不会
我是一名优秀的程序员,十分优秀!