我在main.xml中定義的RelativeLayout的:設定位置編程
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical" android:layout_width="fill_parent"
android:layout_height="fill_parent">
</RelativeLayout>
並添加編程中的onCreate一個TextView和EditText上:
public void onCreate(Bundle savedInstanceState){
setContentView(R.layout.main);
addContentView(customGlView, new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
addContentView(myTextView, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
addContentView(myEditText, new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
}
他們都出現,但在左上角重疊。我花了好幾個小時才弄清楚如何將它們放置在彼此的下方,或者一個放在屏幕的左下角,另一個放在右下角。如果我通過main.xml添加它們,它們都不會顯示出來。任何人都可以給我一個正確的方向提示嗎?
這不起作用。我已經通過setId()爲兩個視圖分配了ID,就像在Raoul Georges的答案中一樣,但它們仍然是相互重疊的。 – Lennart 2012-02-01 11:02:17
嗯,很奇怪。你確定你使用了不同的LayoutParams變量嗎?如果你重複使用相同的結果,你會得到不可預知的結果 – Guillaume 2012-02-01 11:14:39
是的,我爲每一個使用了一個不同的LayoutParams。一個是BELOW,另一個是ABOVE。 – Lennart 2012-02-01 11:20:07