Android 添加子视图后调整相对布局的大小
我有一个扩展RelativeLayout的自定义视图。 在使用xml布局将其膨胀之后,我想向其添加另一个视图。 我想在现有视图的上方添加视图。 这似乎可行,但RelativeLayout不会自行调整大小。 看起来旧的内容会被覆盖,或者向下滚动 不可见 我通过以下方式创建自定义RelativeLayout: 公共类BottomBarEdit扩展了RelativeLayout{Android 添加子视图后调整相对布局的大小,android,view,android-relativelayout,Android,View,Android Relativelayout,我有一个扩展RelativeLayout的自定义视图。 在使用xml布局将其膨胀之后,我想向其添加另一个视图。 我想在现有视图的上方添加视图。 这似乎可行,但RelativeLayout不会自行调整大小。 看起来旧的内容会被覆盖,或者向下滚动 不可见 我通过以下方式创建自定义RelativeLayout: 公共类BottomBarEdit扩展了RelativeLayout{ private Context context; public BottomBarEdit(Context conte
private Context context;
public BottomBarEdit(Context context, AttributeSet attrs, int defStyle) {
super(context, attrs, defStyle);
this.context = context;
View.inflate(context, R.layout.lay_bottom_bar_edit, this);
我尝试通过以下方式动态添加视图:
// create layout parameters
RelativeLayout.LayoutParams lparams = new RelativeLayout.LayoutParams(
RelativeLayout.LayoutParams.FILL_PARENT,
RelativeLayout.LayoutParams.WRAP_CONTENT);
lparams.addRule(RelativeLayout.ALIGN_PARENT_RIGHT);
lparams.addRule(RelativeLayout.ALIGN_PARENT_TOP);
lparams.addRule(RelativeLayout.ABOVE, R.id.bottom_bar_buttons);
// RelativeLayout editMain = (RelativeLayout)
// findViewById(R.id.bottom_bar_edit);
LayoutInflater inflater = (LayoutInflater) context
.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
View noteBar = inflater.inflate(R.layout.lay_bottom_bar_notes, null);
this.addView(noteBar, lparams);
知道出了什么问题吗?
谢谢!我有同样的问题。但您也应该向我们展示您的布局XML。