回答
这是答案,但不是直接的答案。这是我亲自做的以编程方式创建复杂的布局。
在XML中创建相同的布局。
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >
<ImageView
android:id="@+id/imageView1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:src="@drawable/some_big_image" />
<RelativeLayout
android:layout_width="match_parent"
android:layout_height="100dp"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true"
android:background="#DD000000" >
<ImageView
android:id="@+id/imageView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:src="@drawable/ic_launcher" />
<TextView
android:id="@+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="@+id/imageView2"
android:layout_toRightOf="@+id/imageView2"
android:text="TextView"
android:textColor="@android:color/white" />
<TextView
android:id="@+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="@+id/imageView2"
android:layout_toRightOf="@+id/imageView2"
android:text="TextView"
android:textColor="@android:color/white" />
</RelativeLayout>
现在从顶级父到孩子。
RelativeLayout mParent = new RelativeLayout(this);
RelativeLayout.LayoutParams mParentParams = new RelativeLayout.LayoutParams(new RelativeLayout.LayoutParams(RelativeLayout.LayoutParams.MATCH_PARENT, RelativeLayout.LayoutParams.MATCH_PARENT));
mParent.setLayoutParams(mParentParams);
ImageView mBigImageView = new ImageView(this);
mBigImageView.setLayoutParams(mParentParams);
mParent.addView(mBigImageView);
正如你实践您可以直接代码,而无需创建XML一样。
你可以有一个相对布局,其中包含一个大图像的图像视图在它的下面,一个更多的线性布局包含图像和文字作为“珍珠大陆...”和班轮布局的背景应该是50-60%透明。 使用形状为LL创建背景。并将其设置为对齐父级(相对)布局的底部。 希望这可以帮到你
其实我不知道如何添加这些类型的参数,android:layout_alignBottom,android:layout_alignLeft等 – Yawar
它更好地在xml中创建布局,然后在需要的地方膨胀。充气后设置各项所需的值 –
另外还有一个样本提供了上面的 –
- 1. 如何以编程方式设计布局,android?
- 2. 以编程方式设置布局
- 3. Android以编程方式添加布局?
- 4. Android:如何以编程方式设置布局的大小
- 5. 以编程方式在android中设置布局的大小
- 6. 以编程方式为Android设置布局
- 7. 设置叠起来的布局以编程方式在Android的
- 8. Android以编程方式设置按钮布局
- 9. Android - 以编程方式设置布局标签
- 10. 以编程方式设置android的布局参数
- 11. Android布局 - 以编程方式设置自定义布局组件的值
- 12. 以编程方式创建布局设计支持android中的所有屏幕
- 13. 以编程方式生成布局(XAML)
- 14. 以编程方式自动布局
- 15. 以编程方式分析CSS布局
- 16. 以编程方式创建布局
- 17. 以编程方式安排TextView布局
- 18. IOS以编程方式插入布局
- 19. UICollectionViewCell以编程方式自动布局
- 20. 以编程方式编辑Android SFGameView布局
- 21. 约束布局 - 以编程方式设置指南的方向
- 22. 以编程方式膨胀以获得android布局
- 23. Android设计布局
- 24. 设计布局android
- 25. Android布局设计
- 26. 以编程方式将布局加载到另一个布局
- 27. 以编程方式更改布局的布局颜色
- 28. 以编程方式设置TextView的布局权重
- 29. 以编程方式设置向导布局模板
- 30. ios自动布局:以编程方式设置宽度约束
为什么图像没有显示?你有没有人看到这个图像,这个问题与我一起? – Yawar
我可以看到图像。但你应该多解释一下。哪些部分是布局元素,什么是静态图片?几乎所有事情都可以用'RelativeLayout' –
实际上我不知道如何添加这些类型的参数,android:layout_alignBottom,android:layout_alignLeft等 – Yawar