0

I am having some problems with setting a view's height:

It seems that the number that I set on the LayoutParams does not correspond to the x and y coordinates on the screen.

For example: when I set a View's height to 10 and then set another view's y coordinates to the first View's coordinates + 10, it positions the view with an offset on the y axis.

But when I use View.getHeight() and set another views coordinates to the first view's coordinates + v.getHeight() it has no offset.

Are the layoutparams Height density-dependent?

EDIT

This is what I do:

    view1.getLayoutParams().height = Height + MainActivity.pixels;
    if (MainActivity.connections [i] != 0){
        int SiblingY = (int) view1.getY() + Height + MainActivity.pixels;
        view2.setY(SiblingY);

When I do this, view2's top does not allign perfectly with view1's bottom.

But if I do:

        int SiblingY = view1.getX + view1.getHeight();
        vMoved.setY(SiblingY);

It works perfectly, the problem is that the latter needs to be done after the Height changes on the screen, so I have to execute that on another event.

Sochimickox
  • 135
  • 1
  • 2
  • 9
  • You're probably doing `getHeight()` or `getWidth()` before the View is laid out (and will have a width/height of 0). – Kevin Coppock Feb 13 '14 at 01:52
  • What I am trying to do is to position a View below another one, by doing the first thing, it positions it below but with some offset. When I do the second thing, it positions the top of the second view just below the bottom of the first one, that is what I want. – Sochimickox Feb 13 '14 at 01:57
  • @kcoppock also, I cant use getHeight() because I am doing this all inside one touch event so the getHeight method updates only when it finishes and it gets redrawn – Sochimickox Feb 13 '14 at 01:58
  • 1
    For the record, the view's coordinates are in relation to its parent, not the screen, and second, the fact that you "can't use getHeight()" means the architecture of what you're trying to accomplish my be wrong. Maybe if you provide some code and a better description of what you've done, what you've tried and what you want, people may be able to help you better :) – Martin Marconcini Feb 13 '14 at 02:02

0 Answers0