I am having three images or buttons in a linear layout which fits fine on large devices, but when it comes to small devices, what should i do so that the third image comes in the next line (in small devices, it would be aligned properly in landscape but it would go out of the screen in the portrait mode).

XML code:
<LinearLayout
android:id="@+id/linearLayout7"
android:layout_width="fill_parent"
android:layout_height="wrap_content" android:layout_marginLeft="5dp" android:layout_marginRight="5dp" android:layout_marginBottom="5dp" android:gravity="left" android:layout_gravity="left" android:fitsSystemWindows="true">
<ImageButton
android:id="@+id/stopServiceButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/stop_service_button_selector" android:background="@null" android:layout_gravity="left" android:paddingBottom="5dp" android:paddingRight="5dp" android:paddingTop="5dp"/>
<ImageButton
android:id="@+id/calibrateButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/calibrate_button_selector" android:background="@null" android:layout_gravity="left" android:padding="5dp"/>
<ImageButton
android:id="@+id/doneButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@drawable/done_button_selector" android:background="@null" android:layout_gravity="left" android:padding="5dp"/>
</LinearLayout>
One simple way is to use
layout_weightattribute,this way