Android:拆分ActionBar真正的父母身高(Android: Split ActionBar real parent height)

编程入门 行业动态 更新时间:2024-10-25 00:36:38
Android:拆分ActionBar真正的父母身高(Android: Split ActionBar real parent height)

我使用操作栏(原始android,而不是ABS),并将我的视图相对放置在根布局( RelativeLayout )上。 为了计算屏幕上的相对位置,我使用了我的视图的getParent().getHeight() / getParent().getWidth()方法。 使用正常的ActionBar它工作正常。 我得到父级的真实高度(活动高度 - 操作栏高度,例如800px显示器上的690px)。 但是,如果我使用splitActionBarWhenNarrow选项,并显示底部栏,我会得到父级的相同高度(例如,在800像素的屏幕上再次显示690像素)。 因此,我的一些编程定位点位于底部的操作栏下。

我怎样才能得到父母的真正高度,没有操作栏?

编辑:

我读取了activity的onWindowFocusChanged方法的父宽度和高度。

I use the action bar (origin android, not ABS) and position my views relatively on the root layout (RelativeLayout). To calculate the relative position on the screen I used the getParent().getHeight() / getParent().getWidth() methods of my view. With the normal ActionBar it works fine. I get the real height of the parent (Activity height - Actionbar hight, e.g. 690px on the 800px display). But if I use the splitActionBarWhenNarrow option and the bottom bar is shown I get the same height of the parent (e.g. again 690px on the 800px screen). So some of my programmatically positioned vies are under the bottom action bar.

How can I get the real height of the parent, without the action bars?

Edit:

I read the parent width and height on the onWindowFocusChanged method of the activity.

最满意答案

顶部和底部的操作栏都是相同的高度。 据我所知,你不能以编程方式请求操作栏的大小。 这篇文章举例说明了如何使用样式设置动作栏高度,以保持一致。

要确定操作栏是否已拆分,您必须手动计算。 根据设计指南 (靠近底部)

主要操作栏中可以容纳多少动作? 操作栏容量由以下规则控制:

主操作栏中的操作按钮可能不会占用酒吧宽度的50%以上。 底部动作条上的动作按钮可以使用整个宽度。

与密度无关的像素(dp)中的屏幕宽度决定了适合主操作栏的项目数量:

小于360 dp = 2个图标

360-499 DP = 3个图标

500-599 dp = 4个图标

600 dp和更大= 5个图标

例: 例子表

所以你想要做这样的事情。

DisplayMetrics displayMetrics = new DisplayMetrics(); Display display = getWindowManager().getDefaultDisplay(); display.getMetrics(displayMetrics); float density = displayMetrics.density; // width in dp float width = (displayMetrics.widthPixels / density); // I will assume you have 3 action bar icons if (width < 360) { // 2 menu items fit. // Calculate action bar height with 2*(actionbar height) // to accommodate the bottom action bar. } else { // 3+ menu items fit // Calculate action bar height with 1*(actionbar height). }

Both the top and bottom action bar are the same height. As far as I know, you can not request the size of the action bar programmatically. This post gives an example of how to set the action bar height with a style so that it is consistent.

To determine whether or not the action bar has been split, you must calculate this manually. As per the design guidelines (near the bottom)

How many actions will fit in the main action bar? Action bar capacity is controlled by the following rules:

Action buttons in the main action bar may not occupy more than 50% of the bar's width. Action buttons on bottom action bars can use the entire width.

The screen width in density-independent pixels (dp) determine the number of items that will fit in the main action bar:

smaller than 360 dp = 2 icons

360-499 dp = 3 icons

500-599 dp = 4 icons

600 dp and larger = 5 icons

Example: table of examples

So you want to do something like this.

DisplayMetrics displayMetrics = new DisplayMetrics(); Display display = getWindowManager().getDefaultDisplay(); display.getMetrics(displayMetrics); float density = displayMetrics.density; // width in dp float width = (displayMetrics.widthPixels / density); // I will assume you have 3 action bar icons if (width < 360) { // 2 menu items fit. // Calculate action bar height with 2*(actionbar height) // to accommodate the bottom action bar. } else { // 3+ menu items fit // Calculate action bar height with 1*(actionbar height). }

更多推荐

本文发布于:2023-08-05 00:30:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1424608.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:身高   父母   ActionBar   Android   height

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!