[英]How to add view created programatically on to relativelayout in xml and below a specific component
I am having a RelativLayout in xml file with several components. 我在xml文件中有一个带有几个组件的RelativLayout。 Now one view created programatically should be added below specific component in activity view.
现在,应将以编程方式创建的一个视图添加到活动视图中特定组件的下方。
To be precise, 确切地说,
XML having RelativeLayout with one LinearLayout. XML具有RelativeLayout和一个LinearLayout。
Programatically created view in java code needs to be added below this LinearLayout. 需要在此LinearLayout下方添加以Java代码编程创建的视图。
How to achieve this requirement. 如何达到这一要求。
Thanks in advance. 提前致谢。
create another linearlayout in xml below first layout. 在第一个布局下方的xml中创建另一个linearlayout。 and add your component in that layout
并在该布局中添加您的组件
When you add the new view, you can add a new rule to it 添加新视图时,可以向其添加新规则
View foo = new View();
RelativeLayout.LayoutParams p = new RelativeLayout.LayoutParams(ViewGroup.LayoutParams.WRAP_CONTENT,ViewGroup.LayoutParams.WRAP_CONTENT);
p.addRule(RelativeLayout.BELOW, R.id.your_view);
foo.setLayoutParams(p);
Please try this, may be help you I use imageView but you add any other view that you required. 请尝试此操作,这可能对您使用我的imageView有帮助,但是您需要添加任何其他视图。
LinearLayout view = (LinearLayout) findViewById(R.id.layout);
ImageView myImage = new ImageView(this);
LinearLayout.LayoutParams parms = new LinearLayout.LayoutParams(105, 105);
parms.setMargins(5, 5, 5, 5);
myImage.setLayoutParams(parms);
myImage.setBackgroundColor(Color.TRANSPARENT);
myImage.setImageBitmap(bitmap);
view.addView(myImage);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.