I need to set the width of my view to 50% of the width of the screen, and then center this image horizontally, with the possible presence of 1 or more buttons that can be displayed on the left or right side of the screen.
I use relative layout so that I can place a linear layout with weights to get 50% centering by placing any buttons on top of this LL attached to the left or right edge of the RL. However, there is no blue middle bar in this layout. If I set the average layout_weight layout to 1, I get 3 bars of equal size.
<RelativeLayout android:layout_width="match_parent" android:layout_height="48dp"> <LinearLayout android:id="@+id/stupid_android" android:orientation="horizontal" android:layout_width="match_parent" android:layout_height="match_parent" > <View android:layout_width="fill_parent" android:layout_height="match_parent" android:background="#FF0000" android:layout_weight="1" /> <View android:layout_width="fill_parent" android:layout_height="match_parent" android:background="#0000FF" android:layout_weight="2" /> <View android:layout_width="fill_parent" android:layout_height="match_parent" android:background="#00FF00" android:layout_weight="1" /> </LinearLayout> </RelativeLayout>
source share