문제

I have an android dialog which i want to position in a specific position in its window.

I'm using API 8

how come int a == -2 and int b == 153 are not positive?

what is the difference between

getLayoutParams().height;
    mToolTipLayout.getHeight();

I have the following code

  public void initViews(int orientation) {

    mToolTipLayout = ((LinearLayout) findViewById(R.id.tooltip_layout));

    ViewTreeObserver vto = mToolTipLayout.getViewTreeObserver();
    vto.addOnGlobalLayoutListener(new OnGlobalLayoutListener() {
      @Override
      public void onGlobalLayout() {
        mToolTipLayout.getViewTreeObserver().removeGlobalOnLayoutListener(this);
        setPosition();
      }
    });


  private void setPosition() {
    int a = mToolTipLayout.getLayoutParams().height;
int b = mToolTipLayout.getHeight();

  }
도움이 되었습니까?

해결책

Layout params specify how the measure and layout process should work. They are not updated in the measure/layout process. -2 is the value for WRAP_CONTENT.

The measures themselves are available in the views themselves, not their layout params. 153 is the measured pixel height in your case, measured with WRAP_CONTENT spec.

다른 팁

Yes, -2 means WRAP_CONTENT. To get a height of a layout in this case you cannot use getLayoutParams().height or getHeight() (-2 and 0 respectively). You should get a height of inner view (for instance, with view.getLayoutParams().height). Probably add paddings.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top