我的应用布局,整体上是一个LinearLayout, 如下面这样,每个控件占一行。可是我希望,有些Lable和输入控件本身,如下面的:作为Lable的TextView和EditText,能放在同一行,左右排列。
因为这样,一是更省画面空间,二是也更符合传统习惯。
不知该怎么修改Layout文件?请高手TX指点。
<LinearLayout android:layout_height="fill_parent" 
              android:layout_width="fill_parent" 
              android:orientation="vertical" 
              android:id="@+id/viewPage1" 
              xmlns:android="http://schemas.android.com/apk/res/android">
 
  <TextView android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:text="@string/label_income_amount" 
            android:layout_marginTop="5sp"> </TextView>   <EditText android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:id="@+id/src_amount" 
            android:hint="@string/src_amount_hint"/> 
  <TextView android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:text="@string/label_discount_amount"> </TextView>   <EditText android:layout_height="wrap_content" 
            android:layout_width="fill_parent" 
            android:id="@+id/src_amount_discount" 
            android:hint="@string/src_amount_hint"/>  ......</LinearLayout>

解决方案 »

  1.   

    <LinearLayout android:layout_height="fill_parent" 
                  android:layout_width="fill_parent" 
                  android:orientation="vertical" 
                  android:id="@+id/viewPage1" 
                  xmlns:android="http://schemas.android.com/apk/res/android">
     
     <LinearLayout android:orientation="horizontal"
      <TextView android:layout_height="wrap_content" 
                android:layout_width="fill_parent" 
                android:text="@string/label_discount_amount"> </TextView>   <EditText android:layout_height="wrap_content" 
                android:layout_width="fill_parent" 
                android:id="@+id/src_amount_discount" 
                android:hint="@string/src_amount_hint"/>
    </LinearLayout>
      ......</LinearLayout>
      

  2.   

        <LinearLayout
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal" >        <Button
                android:id="@+id/button1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="LeftButton" />        <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="match_parent"
                android:layout_weight="1" >        </LinearLayout>        <Button
                android:id="@+id/button2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="RightButton" />
        </LinearLayout>
    这样可以达到左右对齐的效果~~~~~~~~~~~~