1
CustomView(Context c, Boolean animate) {
    super(c);
    this.animate = animate;
    p = new Paint();
    p.setColor(Color.BLACK);
    setLayoutParams(new ActionBar.LayoutParams(100, 100));
    setPivotX(getX() + getWidth() / 2);
    setPivotY(getY() + getHeight() / 2);
    if(animate)
    {
        post(this);
    }
}

in my constructor first I set the layout params 100x100, then I want to set the pivot point into the center, but the getWidth() and getHeight() returns 0, thus as if the setLayoutParams() didn't worked, why this happens? cause I have to hardcode the size I want

1 Answers1

0

Read this question regarding the necessity of the three different constructors for custom views. It's very likely your constructor isn't getting called if you're not directly instantiating the view yourself (ie. you've defined it in a .xml layout).

Community
  • 1
  • 1
Austin Hanson
  • 21,820
  • 6
  • 35
  • 41