添加链接
link之家
链接快照平台
  • 输入网页链接,自动生成快照
  • 标签化管理网页链接
Collectives™ on Stack Overflow

Find centralized, trusted content and collaborate around the technologies you use most.

Learn more about Collectives

Teams

Q&A for work

Connect and share knowledge within a single location that is structured and easy to search.

Learn more about Teams

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();
                I would agree with using a PopupWindow for this behavior, but for calculation of a window, you should read the documentation. I believe its the onResume() in which the values for the LayoutParms actually get updated for the given view/window.
– JoxTraex
                May 14, 2014 at 9:59
                I think Dialog is by default shown screen center if you show such kind of popup/dialog at specific location then you prefer PopupWindow.
– Haresh Chhelana
                May 15, 2014 at 6:57

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.

thanks. so in that case getLayoutParams().height; and mToolTipLayout.getHeight(); return the same? – Elad Benda May 15, 2014 at 6:45 Possibly but not necessarily - the measure process won't always give you exactly the specific size requested via layout params. – laalto May 15, 2014 at 6:48

Thanks for contributing an answer to Stack Overflow!

  • Please be sure to answer the question. Provide details and share your research!

But avoid

  • Asking for help, clarification, or responding to other answers.
  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.