質問

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