i want to make layout like picture but just use relative and linear layout.i want to mak 4 equal parts.I do not want to just put 4 button ot other objects.iwant just 4 equal space.
Asked
Active
Viewed 202 times
-5
-
why just a negative vote?help please – soft_94 Feb 20 '17 at 09:08
-
1Possible duplicate of [Align Buttons horizontally with equal spacing in linearlayout](http://stackoverflow.com/questions/15749942/align-buttons-horizontally-with-equal-spacing-in-linearlayout) – Mohammed Atif Feb 20 '17 at 09:09
-
see edit please @MohammedAtif – soft_94 Feb 20 '17 at 09:13
-
Make a generic LinearLayout, with a weight of 100, inside put other 2 linear that keep 50% of 100, inside these 2 new LinearLayout do the same thing but align them horizontally. Thank just assign a background color – Mitro Feb 20 '17 at 09:20
-
@Mitro thanks a lot!you save my time,i am new to android ;) – soft_94 Feb 20 '17 at 09:24
-
@soft_94 I wrote the sample as answer, you can see, good luck – Mitro Feb 20 '17 at 09:30
3 Answers
0
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout
xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:local="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:weightSum="2"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2"
>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/red"
/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/black"
/>
<LinearLayout
android:layout_height="0dp"
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_weight="1"
android:weightSum="2"
>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/green"
/>
<LinearLayout
android:layout_height="match_parent"
android:layout_width="0dp"
android:layout_weight="1"
android:background="@color/yellow"
/>
</LinearLayout>
try this.

aj0822ArpitJoshi
- 1,142
- 1
- 9
- 25
0
This is my solution I state in the comment, as you can see is a nest of LinearLayouts
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/activity_main"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:weightSum="100"
android:paddingBottom="@dimen/activity_vertical_margin"
android:paddingLeft="@dimen/activity_horizontal_margin"
android:paddingRight="@dimen/activity_horizontal_margin"
android:paddingTop="@dimen/activity_vertical_margin"
android:orientation="vertical"
tools:context="net.whatsgift.mitro.weightlayout.MainActivity">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:backgroundTint="@color/colorAccent"></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:backgroundTint="@color/colorPrimary"></LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:orientation="horizontal"
android:weightSum="100">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:backgroundTint=""></LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="50"
android:backgroundTint="@color/colorAccent"></LinearLayout>
</LinearLayout>
</LinearLayout>

Mitro
- 1,230
- 8
- 32
- 61
0
Use below Layout XML file just like your Image.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#F3FF33">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#FF333F">
</RelativeLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal"
android:weightSum="2">
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#D5DA87">
</RelativeLayout>
<RelativeLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#1BE114">
</RelativeLayout>
</LinearLayout>
</LinearLayout>

Chetan Joshi
- 5,582
- 4
- 30
- 43
-
if above code is working for you then please accept or upvote it. – Chetan Joshi Feb 20 '17 at 09:42