kev
kev

Reputation: 155

Android: Align spinner and a button on the same row?

How to align spinner and a button in one row using linear layout? Here's the code:

<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>

Upvotes: 1

Views: 2066

Answers (3)

RajaReddy PolamReddy
RajaReddy PolamReddy

Reputation: 22493

try this

<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>

Upvotes: 0

Vinay
Vinay

Reputation: 2415

Just set orientation as horizontal.

Upvotes: 0

Yashwanth Kumar
Yashwanth Kumar

Reputation: 29121

<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>

change orientation to horizontal? or don't mention anything, default is horizontal.

Upvotes: 2

Related Questions