Reputation: 163
UPDATING the question: I know that LinearLayout is much better and already implemented it with linear. I have an educational task that requires RelativeLaouyt implementation. Please, don't comment about Linear layout, this is not the purpose of my question.
I know that it much easier in LinearLayout, but I have to implement it with RelativeLayout only. I have 3 buttons in my xml file and want them on the same line and to have the same width that equals to 1/3 of the screen.
(I found here a nice solution for 2 buttons using a "fake" view. But it doesn't work for 3 buttons.)
Any ideas? (relative layout only!)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_margin="10dp">
<Button
android:id="@+id/bottom_left"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Left"/>
<Button
android:id="@+id/bottom_center"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_centerInParent="true"
android:text="Center"/>
<Button
android:id="@+id/bottom_right"
android:layout_width="100dp"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:layout_alignParentRight="true"
android:text="Right"/>
</RelativeLayout>
Upvotes: 0
Views: 3115
Reputation: 124
With reference to your link provided for 2 buttons, you can also use the same for 3 buttons using Relative layout. The answer could be, set 3 different properties of relative layout to each view. For instance, Button 1: alignParentLeft true Button 2: centreInParent true Button 3: alignParentRight true
You are partially right, centerInParent is the property you need. Thanks.
Upvotes: 1