- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
所以我正在搜索抛出所有 getHeight/widht 问题帖子,并尝试不同的方法来解决问题(如 globalLayoutListener 或 Runnable),等待,直到 FrameLayout 被创建......但仍然是我的getHeight 返回 0。所以这是我现在的代码:
private void zurechtruecken() {
int n=1;
spB =(FrameLayout) findViewById(R.id.spielbereich);
spB.post(new Runnable(){
@Override
public void run(){
spielBh=spB.getMeasuredHeight();
spielBb=spB.getMeasuredWidth();
}
});
这是我使用 GlobalLayoutListener 的代码:
private void zurechtruecken() {
int i=24;
int n=1;
mView = findViewById(R.id.spielbereich);
mView.getViewTreeObserver().addOnGlobalLayoutListener(
new OnGlobalLayoutListener(){
@Override
public void onGlobalLayout() {
mView.getViewTreeObserver().removeGlobalOnLayoutListener(this);
spielBh=mView.getHeight();
spielBb=mView.getWidth();
Log.i("!",Integer.toString(spielBh));
Log.i("!",Integer.toString(spielBb));
}
});
“removeGlobalLayoutListener(this)”被交叉。(已弃用)
我测量框架布局可能很重要
<小时/>感谢您的帮助!波蒂560
最佳答案
我以前也遇到过这样的麻烦。如果所有其他方法都失败,请在您自己的类中扩展 FrameLayout 并在 onMeasure 方法中获取高度/宽度值。示例:
@Override
protected void onMeasure(int widthMeasureSpec, int heightMeasureSpec) {
super.onMeasure(widthMeasureSpec, heightMeasureSpec);
int height = MeasureSpec.getSize(heightMeasureSpec);
}
也可以轻松地将其放入 XML 布局中,例如:
<com.yourdomain.yourappname.FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" > ...
关于java - getHeight 和 getMeasuredHeight 返回 0,即使在 Runnable 中也是如此,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27342571/
我正在尝试确定某些 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,扩展以
我是一名优秀的程序员,十分优秀!