Wednesday, 21 August 2013

LinearLayout's width and height are zero

LinearLayout's width and height are zero

I have the problem, that if I try to get my height and width with
LinearLayout.getWidth() and LinearLayout.getHeight(), the int I get is 0.
This is my onCreat:
@Override
protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);
View mainView = getLayoutInflater().inflate(R.layout.activity_game,
null);
LinearLayout container = (LinearLayout)
mainView.findViewById(R.id.container);
view = new GameLayout(this, container.getWidth(), container.getHeight());
container.addView(view);
setContentView(mainView);
view.setOnClickListener(this);
}
If you have any idea, what I am doing wrong, pls help.
I need this for getting the size of my Layout, because I want, to position
my Bitmap at the same percental place on every device (for example every
time at the exact center of the screen).

No comments:

Post a Comment