简体   繁体   English

如何将以编程方式创建的视图添加到xml中及特定组件下方的relativelayout上

[英]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.

相关问题 RelativeLayout 在另一个下方添加多个视图 - RelativeLayout add multiple view one below another 将两个视图添加到RelativeLayout.BELOW - Add two View to RelativeLayout.BELOW 如何以编程方式向Android导航视图中的findViewById将菜单项添加到XML创建的子菜单中? - How to programatically add menu item to submenu that is created in XML by findViewById in Android Navigation View? 如何通过添加另一个视图以编程方式添加到XML? - How to add to an XML programatically by adding another View? 如何在Android中的RelativeLayout中的TextView下对齐视图 - How to align a View below a TextView in a RelativeLayout in Android 如何以编程方式添加以下布局 - How to add below layout programatically 如何以编程方式将视图添加到RelativeLayout? - How to add a view programmatically to RelativeLayout? 我们如何在relativelayout的listview下面添加自定义视图(从gif图片下载的URL格式) - how can we add custom view (of gif image downloaded form url) below listview in relativelayout 如何在RelativeLayout中删除动态创建的视图 - How to remove dynamically created view within RelativeLayout RelativeLayout中的Textviews不会以编程方式出现在彼此下方 - Textviews in RelativeLayout not appearing below each other programatically
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM