2012-01-17 116 views

回答

2

首先創建一個TableLayout,把TextView1,EditText1,TextView2 & EditText2在裏面。 TableLayout使用正常的相對佈局添加提交按鈕&確保將按鈕的重力更改爲居中水平。

+0

DAS需要在運行時做 – 2012-01-17 09:50:13

1

有很多方法可以做到這一點。就個人而言,我會窩,像這樣的一些佈局(注意:不是真正的代碼,只是爲了傳達出點):

<LinearLayout orientation:vertical > 
    <LinearLayout orientation:horizontal> 
     <TextView layout_width="0" layout_weight="1" /> 
     <EditText layout_width="0" layout_weight="1" /> 
    </LinearLayout> 

    <LinearLayout orientation:horizontal> 
     <TextView layout_width="0" layout_weight="1" /> 
     <EditText layout_width="0" layout_weight="1" /> 
    </LinearLayout> 

    <LinearLayout> 
     <Button layout_gravity="center_horizontal" /> 
    </LinearLayout> 
</LinearLayout> 

設置所有LinearLayouts來填充屏幕寬度方向和包裹的內容或設置自己的垂直間隔。

3

把這個代碼在你onCreate()

ScrollView sv = new ScrollView(this); 

LinearLayout ll = new LinearLayout(this); 

ll.setOrientation(LinearLayout.VERTICAL); 
sv.addView(ll); 

TextView tv = new TextView(this); 

tv.setText("Dynamic layouts ftw!"); 

ll.addView(tv); 

EditText et = new EditText(this); 

et.setText("weeeeeeeeeee~!"); 

ll.addView(et); 


this.setContentView(sv); 
0

使用在佈局xml文件中下面的代碼:

<LinearLayout android:orientation="horizontal" > 
    <LinearLayout android:orientation="vertical"> 
     <TextView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     <TextView android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
     <EditText layout_width="0" layout_weight="1" /> 
    </LinearLayout> 

    <LinearLayout android:orientation="horizontal" > 
     <EditText android:layout_width="200" 
       android:layout_height="wrap_content" /> 
     <EditText android:layout_width="200" 
       android:layout_height="wrap_content" /> 
    </LinearLayout> 

    <LinearLayout android:layout_gravity="center_horizontal"> 
     <Button android:layout_width="wrap_content" 
       android:layout_height="wrap_content" /> 
    </LinearLayout> 
</LinearLayout>