I’m trying to horizontally place views inside a linear layout such that I can align these views horizontally but not next to each other. I tried giving margin,padding values etc. but nothing worked for me. All the views remain placed next to each other.
I want the digital clock in the extreme right and the WiFi image in the center.
Please suggest what should I use to align views with separation within them using minimum hard code.
<LinearLayout
android:id="@+id/top_bar_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/top_bar"
android:orientation="horizontal" >
<ImageView
android:id="@+id/signal_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/signal1" />
<ImageView
android:id="@+id/nosim_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageView
android:id="@+id/wifi_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/wifi1" />
<ImageView
android:id="@+id/battery_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:background="@drawable/battery1"
/>
<DigitalClock
android:id="@+id/digClock_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
/>
</LinearLayout>
If you want to align things more
Relatively, so that something is always at the left edge, and so on, you should use a RelativeLayout. It gives you more flexibility to work on things like that.