我有兩個相對佈局,當前顯示爲一個在另一個之下。我希望第二個佈局以編程方式顯示在第一個相對佈局的右側。以編程方式在另一個相對佈局旁放置一個相對佈局
以下是我使用的代碼。
main.xml中
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RelativeLayout
android:layout_width="620dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/lay1" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello1" />
</RelativeLayout>
<RelativeLayout
android:layout_width="620dp"
android:layout_height="wrap_content"
android:orientation="vertical"
android:id="@+id/lay2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/hello2" />
</RelativeLayout>
</LinearLayout>
myAct.java
public class myAct extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
LinearLayout layoutContainer = new LinearLayout(this);
layoutContainer.setLayoutParams(new LinearLayout.LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.FILL_PARENT));
// Arguments here: width, height, weight
LinearLayout.LayoutParams childLp = new LinearLayout.LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
RelativeLayout layoutLeft = new RelativeLayout(this);
layoutContainer.addView(layoutLeft, childLp);
RelativeLayout layoutRight = new RelativeLayout(this);
layoutContainer.addView(layoutRight, childLp);
}
}
在此先感謝
謝謝Tony..it工程... :-) – JKV 2011-12-30 07:31:22
@jinsi這似乎是愚蠢的。爲什麼你在標題中添加了** programaticcaly **? :-) – 2011-12-30 07:40:35
現在我有n個相對的佈局,我想在兩排佈局中排列。誰能幫我嗎... – JKV 2011-12-30 08:51:12