- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我写了一个非常简单的 View 组扩展 LinearLayout 如下。
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
ViewParent viewParent = getParent();
if(viewParent instanceof RelativeLayout)
{
RelativeLayout parentLayout = (RelativeLayout)viewParent;
int widthSize = MeasureSpec.getSize(widthMeasureSpec);
Log.d(Constants.TAG, "Parent height is " + parentLayout.getMeasuredHeight());
Log.d(Constants.TAG, "Parent height is1 " + parentLayout.getHeight());
int height = parentLayout.getMeasuredHeight();
// getChildAt(0).measure(MeasureSpec.EXACTLY | AndroidUtilities.dp(70), MeasureSpec.EXACTLY | (int)(parentLayout.getMeasuredHeight()*0.6));
// getChildAt(1).measure(MeasureSpec.EXACTLY | AndroidUtilities.dp(70), MeasureSpec.EXACTLY | (int)(parentLayout.getMeasuredHeight()*0.4));
getChildAt(0).measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(70), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int)(height* 0.6), MeasureSpec.EXACTLY));
getChildAt(1).measure(MeasureSpec.makeMeasureSpec(AndroidUtilities.dp(70), MeasureSpec.EXACTLY), MeasureSpec.makeMeasureSpec((int)(height* 0.6), MeasureSpec.EXACTLY));
setMeasuredDimension(widthSize, parentLayout.getMeasuredHeight());
}
此 View 组的父级是包含简单 TextView 的 RelativeLayout
。
在 Android 4.2.2 上,parentLayout.getMeasuredHeight() 返回 16777215。我无法理解这个数字。它适用于更高版本的 Android。
有人遇到过这个吗?
最佳答案
我还没有看到这个,但是文档中有一个关于适合您的场景的错误的注释:
至于 16777215(等于 2^24 - 1),我不确定,但它等于 MEASURED_SIZE_MASK
似乎是一个相当大的巧合。见
http://developer.android.com/reference/android/view/View.html#MEASURED_SIZE_MASK
关于android - getMeasuredHeight() 在 Android 4.2.2 上返回 16777215,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28798288/
我正在尝试确定某些 UI 元素的实际尺寸(以像素为单位)! 这些元素是从 .xml 文件中扩展而来的,并使用倾斜宽度和高度进行初始化,以便 GUI 最终支持多种屏幕尺寸和 dpi (as recomm
我有这样的 XML: 我在方法 onMesure 中获取 View 高度,如下所示: protected void onMeasure(int widthMeasureSpec, int heig
我正在尝试以编程方式获取 ListView 中项目的高度。所以我在我们的网站上提到了一些电子邮寄,我得出了以下代码 private float calcListViewItemsHeight(
{ January 14, 2011... I have given up to use setListViewHeightBasedOnChildren(ListView listView},
我正在经历这个http://developer.android.com/guide/topics/ui/declaring-layout.html当我看到一条线表明高度可以但不一定与测量高度不同时,我
我整个上午都在为 Android 上的这个问题苦苦思索。我有一个 ListView,我需要为其计算高度。 我正在使用这段代码: int totalHeight = 0; for (int size =
我尝试在 onGlobalLayout 中调用 View.getMeasuredHeight 和 View.getHeight。两者都给了我相同的结果。 我想知道,在什么情况下它们的值会有所不同?有没
我正在尝试确定 TextView 在绘制之前 的高度。我正在使用以下代码来做到这一点: TextView textView = (TextView) findViewById(R.id.textvie
我真的对 android 为布局所做的整个测量事情感到困惑。基本上,我想在布局之前获取 View 的实际计算高度和宽度。我需要获得计算出的高度和宽度,因为我有一个隐藏的 LinearLayout,我想
ShadowSpan.java public class ShadowSpan extends ReplacementSpan { public ShadowSpan(int color, Point
我有一个问题。 我希望将行动态添加到 TableLayout。添加这些行时,我需要能够获取 View 的大小,因此我尝试在 onSizeChanged() 期间执行此操作,但新行不显示。所以我尝试了
我在 LinearLayout 中有一个 LinearLayout 并且子 linearlayout 有它的 layout params 其中 height 和 width 定义为 LinearLay
所以我正在搜索抛出所有 getHeight/widht 问题帖子,并尝试不同的方法来解决问题(如 globalLayoutListener 或 Runnable),等待,直到 FrameLayout
我写了一个非常简单的 View 组扩展 LinearLayout 如下。 @Override protected void onMeasure(int widthMeasureSpec, i
在使用 view.measure() 测量具有恒定尺寸 的View 之后,getMeasuredHeight() getMeasureWidth() 返回 0。 layout_view.xml,扩展以
我是一名优秀的程序员,十分优秀!