回答
這是答案,但不是直接的答案。這是我親自做的以編程方式創建複雜的佈局。
在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