当前位置:编程学习 > wap >>

LinearLayout中,如何让作为Lable的TextView,和EditText放在同一行?谢谢!

我的应用布局,整体上是一个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>
--------------------编程问答-------------------- <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> --------------------编程问答-------------------- 外面包一层横向linearlayout --------------------编程问答--------------------
    <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>

这样可以达到左右对齐的效果~~~~~~~~~~~~
补充:移动开发 ,  Android
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,