我遇到了一个奇怪的问题:我有一个从 RelativeLayout 扩展的类。
然后我想像这样添加两个视图:
mButtonTip = new ButtonTip(context, attrs);
mToolTip = new ToolTip(context, attrs);
RelativeLayout.LayoutParams params1 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params1.addRule(RelativeLayout.CENTER_HORIZONTAL, RelativeLayout.TRUE);
RelativeLayout.LayoutParams params2 = new RelativeLayout.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
params2.addRule(RelativeLayout.ALIGN_BOTTOM, mToolTip.getId());
addView(mToolTip, params1);
addView(mButtonTip, params2);
不幸的是,mToolTip 视图已正确放置,但 mButtonTip 不会从布局的左下角移动。
您知道为什么 mButtonTip 视图忽略了我刚刚设置的布局参数吗?