Java 当以编程方式添加视图时,RelativeLayout将忽略上述规则。如何修复此错误?
以下是代码片段:Java 当以编程方式添加视图时,RelativeLayout将忽略上述规则。如何修复此错误?,java,android,Java,Android,以下是代码片段: //The view is created manually LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE); myListView = (ListView) inflater.inflate(R.layout.my_lv_layout, null, false); ... //the ListView is prepare
//The view is created manually
LayoutInflater inflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
myListView = (ListView) inflater.inflate(R.layout.my_lv_layout, null, false);
... //the ListView is prepared (that part of my program works)
RelativeLayout.LayoutParams myListViewParams =
new RelativeLayout.LayoutParams(width, height);
myListViewParams.addRule(RelativeLayout.ABOVE, R.id.button_at_the_bottom_of_the_relative_layout);
//the listView is added here, but it is not above the button, but in the upper
//left corner of the screen (the above-rule is simply ignored)
myRelativeLayout.addView(myListView, myListViewParams);
(但是规则RelativeLayout.ALIGN\u PARENT\u RIGHT
在这里起作用)
在文件my_lv_layout.xml
中,除了宽度和高度属性外,没有定义任何规则
如何解决此问题?无法获取实际问题r.id.button\u在\u的\u底部\u相对布局是相对布局的第一级???如果不是这样的话,规则就不适用了。哦,太尴尬了。是的,按钮在一个线性布局中,我在编写代码时完全忘记了这一点。当你对你的评论做出回答时,我会给你打勾。