Android : Android setX method doesn't work in some situations

on Sunday, September 7, 2014


I extend a Viewgroup and when I use setX in this constructor ,it works well.However it doesn't work when I put the setX method in onMeasure or onLayout methods. Why I need to put it into the latter 2 methods is because that I need to calculate how much I need for setX method.


Thanks for any help!



public class CustomProgressBar extends ViewGroup {
private Context context;
//....
public CustomProgressBar(Context context,AttributeSet attrs) {
super(context,attrs);
this.context=context;
//setX(-200); works here
}
@Override
public void onMeasure(int measureSpecX,int measureSpecY){
//...
// setX(-200); doesn't work here
}


@Override
protected void onLayout(boolean arg0, int l, int t, int r, int b) {
//...
}
}

0 comments:

Post a Comment