matskiv
matskiv

Reputation: 401

Can't change width/height of the view using setLayoutParams

I am trying to make square child inside RelativeLayout(which I extend). On activity start it works ok, but when ad is loaded, my relative layout gets smaller but my code does not affect child. Code from extended RelativeLayout:

protected void onSizeChanged(int w, int h, int oldw, int oldh) {
    int minSize = Math.min(w, h);
    RelativeLayout.LayoutParams layoutParams = (RelativeLayout.LayoutParams) imageViewContainer.getLayoutParams();
    layoutParams.width = minSize;
    layoutParams.height = minSize;
    imageViewContainer.setLayoutParams(layoutParams);
    invalidate();
}

Upvotes: 1

Views: 1804

Answers (1)

Axxxon
Axxxon

Reputation: 733

Try to change the values overriding onMeasure method, also in Your code I would either called measure() or requestLayout() by myself

Upvotes: 6

Related Questions