A picture tells more than a lengthy speech :
I want to align vertically the center of the red part with the middle of the black part. I have no constraint of contai
Finally, I use a more programmatic way to solve this problem, because the size of Views are not fixed.
Here the solution :
The layout :
The code :
red.getViewTreeObserver().addOnGlobalLayoutListener(new ViewTreeObserver.OnGlobalLayoutListener() {
@Override
public void onGlobalLayout() {
red.getViewTreeObserver().removeOnGlobalLayoutListener(this);
LayoutParams params = new LayoutParams(
LayoutParams.MATCH_PARENT,
LayoutParams.WRAP_CONTENT
);
params.setMargins(0, 0, 0, red.getHeight()/2);
black.setLayoutParams(params);
}
});
Thanks for your help ! It helps me found this !