因此,我搜索扔所有的getHeight/widht問題帖子,並嘗試了不同的方法來解決問題(如globalLayoutListener,或Runnable),等待,直到FrameLayout已創建......但是我的的getHeight返回0 所以這是我的代碼現在:getHeight和getMeasuredHeight返回0,即使在Runnable
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(本) 「被橫渡了(它被棄用)
這可能是重要的,那IM測量的幀結構
感謝您的幫助! Botti560
是設置爲我而去之後沒有的FrameLayout的知名度? – 2014-12-07 12:36:06
應該是? - 目前設置爲可見 – Botti560 2014-12-07 12:40:35
您是否嘗試過使用onFinishInflate() – Varundroid 2014-12-07 12:41:04