2011-10-27 28 views
1

如何使用线性布局将微调器和按钮对齐到一行中?下面的代码:Android:将微调器和按钮对齐在同一行上?

<LinearLayout 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:orientation="vertical" 
      android:paddingTop="10dp"> 
      <Spinner 
       android:id="@+id/spinner_delay" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:prompt="@string/time_delay"/> 
      <Button 
       android:id="@+id/button_send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send SMS" 
       android:layout_marginTop="5dp" 
       android:layout_marginLeft="230dp" 
       android:layout_marginRight="5dp"/>  
     </LinearLayout> 

回答

0

试试这个

<LinearLayout     
    android:orientation="horizontal" ///set orientation like this 
    android:layout_height="wrap_content" 
    android:layout_width="fill_parent"   
    android:paddingTop="10dp"> 
    <Spinner 
     android:id="@+id/spinner_delay" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:prompt="@string/time_delay"/> 
    <Button 
     android:id="@+id/button_send" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:text="Send SMS" 
     android:layout_marginTop="5dp" 
     android:layout_marginLeft="230dp" 
     android:layout_marginRight="5dp"/> 
</LinearLayout> 
2
<LinearLayout 
      android:layout_height="wrap_content" 
      android:layout_width="fill_parent" 
      android:paddingTop="10dp"> 
      <Spinner 
       android:id="@+id/spinner_delay" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:prompt="@string/time_delay"/> 
      <Button 
       android:id="@+id/button_send" 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:text="Send SMS" 
       android:layout_marginTop="5dp" 
       android:layout_marginLeft="230dp" 
       android:layout_marginRight="5dp"/>  
     </LinearLayout> 

改变方位水平?或者不提任何事情,默认是水平的。

0

只要设置取向水平。