I have made a radiogroup and inside it I have made two linear layouts and in each linear layout I have added two radio buttons.
But the problem is when I run the app multiple radio buttons get selected i.e. they aren't acting mutually exclusive.
Following is my XML file
<?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_simple_maths_game"
android:layout_width="match_parent" android:layout_height="match_parent"
android:paddingBottom="#dimen/activity_vertical_margin" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin" android:paddingTop="#dimen/activity_vertical_margin"
tools:context="com.example.root.mysimplemathsgame.SimpleMathsGame" android:background="#000"
android:orientation="vertical" android:baselineAligned="false">
<LinearLayout
android:layout_weight="0.4" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="0dp">
<TextView
android:text="#string/mytext" android:id="#+id/tvText"
android:layout_width="wrap_content" android:layout_height="0dp"
android:layout_weight="0.87" android:textColor="#fff"
android:textAppearance="#style/TextAppearance.AppCompat.Large" android:padding="20dp"
android:gravity="center_vertical" android:layout_gravity="center_vertical"
android:textSize="32sp" />
<LinearLayout
android:layout_weight="1" android:background="#fff"
android:layout_width="match_parent" android:layout_height="0dp"
android:orientation="horizontal">
<RadioGroup
android:paddingLeft="30dp" android:id="#+id/rgOptions"
android:layout_width="match_parent" android:layout_height="match_parent">
<LinearLayout
android:layout_weight="1" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="0dp">
<RadioButton
android:layout_weight="1" android:textColor="#000"
android:id="#+id/rb1" android:text="#string/answer1"
android:layout_width="0dp" android:layout_height="match_parent" />
<RadioButton
android:layout_weight="1" android:textColor="#000"
android:id="#+id/rb2" android:text="#string/answer2"
android:layout_width="0dp" android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_weight="1" android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="0dp">
<RadioButton
android:textColor="#000"
android:layout_weight="1" android:layout_gravity="start"
android:id="#+id/rb3" android:text="#string/answer3"
android:layout_width="0dp" android:layout_height="match_parent" />
<RadioButton
android:textColor="#000"
android:layout_weight="1" android:layout_gravity="end"
android:id="#+id/rb4" android:text="#string/answer4"
android:layout_width="0dp" android:layout_height="match_parent" />
</LinearLayout>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent" android:layout_height="wrap_content">
<Button
android:layout_weight="1"
android:text="#string/end" android:id="#+id/bEnd" android:layout_gravity="center_horizontal"
android:layout_width="match_content" android:layout_height="wrap_content" />
</LinearLayout>
RadioGroup is a subclass of Linearlayout. RadioGroup can contain only RadioButton as immediate child for its to work as a group . If you put a layout inside it then will work just as a layout and multiple Radiobuttons can be selected . So the answer to the question remove the LinearLayout . If you want orientation RadioGroup has Orientation attribute inside it you can directly add Orientation inside RadioGroup.
Try This One....
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/activity_simple_maths_game"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:baselineAligned="false"
android:orientation="vertical"
android:weightSum="2">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="horizontal">
<TextView
android:id="#+id/tvText"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:gravity="center_vertical"
android:padding="20dp"
android:text="My Text"
android:textAppearance="#style/TextAppearance.AppCompat.Large"
android:textColor="#000"
android:textSize="32sp" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:orientation="horizontal">
<RadioGroup
android:id="#+id/rgOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:paddingLeft="30dp">
<RadioButton
android:id="#+id/rb1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="answer1"
android:textColor="#000" />
<RadioButton
android:id="#+id/rb2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="answer1"
android:textColor="#000" />
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:orientation="vertical">
<RadioButton
android:id="#+id/rb3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="answer1"
android:textColor="#000" />
<RadioButton
android:id="#+id/rb4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="answer1"
android:textColor="#000" />
</LinearLayout>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:orientation="horizontal">
<Button
android:id="#+id/bEnd"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1"
android:text="end" />
</LinearLayout>
Related
I want a layout like below image for the item of a RecyclerView:
Below is my XML Item script:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:weightSum="1"
android:layout_height="wrap_content">
<TextView
android:id="#+id/t"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="0.5"
android:gravity="center"
android:textColor="#000000"
android:textSize="20sp"
/>
<TextView
android:id="#+id/d"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="0.5"
android:gravity="center"
android:textColor="#000000"
android:textSize="20sp"
/>
</LinearLayout>
What changes to be needed so that vertical and horizontal weight will be applied on layout at same time using Linear Layout?
If you want to use LinearLayout You can use something like this:
[LinearLayout ] [LinearLayout ]
[child 1] [child 1](takes full screen height)
[child 2]
Here is the XML for it:
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="2">
<Button
android:id="#+id/button2"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button"/>
<Button
android:id="#+id/button3"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1"
android:text="Button" />
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:id="#+id/button4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:text="Button" />
</LinearLayout>
</LinearLayout>
It will look like this:
Put it in Linear Layout and provide weight to your each layouts
<LinearLayout
android:weightSum="1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<LinearLayout
android:layout_weight="0.5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:id="#+id/myText"
android:text="Hello"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:textAlignment="center"
android:id="#+id/newText"
android:text="NEW Text"/>
</LinearLayout>
<TextView
android:layout_weight="0.5"
android:layout_width="match_parent"
android:textAlignment="center"
android:layout_height="wrap_content"
android:text="Hello"
android:id="#+id/Newtext"/>
</LinearLayout>
Thank you so much for your helps!
And this is my exact answer from your helps:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:orientation="horizontal" android:layout_width="match_parent"
android:weightSum="1"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="0.4">
<TextView
android:id="#+id/t"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:gravity="center"
android:textColor="#000000"
android:textSize="20sp" />
<TextView
android:id="#+id/d"
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="0.5"
android:gravity="center"
android:textColor="#000000"
android:textSize="20sp" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="0.6">
<TextView
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="0.4"/>
<Switch
android:id="#+id/switch1"
android:layout_width="0dp"
android:layout_height="100dp"
android:layout_weight="0.2"
android:checked="true" />
</LinearLayout>
I want to achieve the following layout.
How do I make the button 0 equal to rest of the buttons. Please note that I have used layout_weight = "1" so that all of the rest of the buttons are of equal length while matching the parent. Since, I have created button 0 on a different layout so I can't seem to make it of equal length with other buttons.
Here's my code so far
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/seven"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/eight"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/nine"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
</LinearLayout>
Take the zero button out of the LinearLayout, I assume there is another layout all this are defined in, like a relative layout? and try something to this effect.
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/linearLayout">
<Button
android:id="#+id/seven"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/eight"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
<Button
android:id="#+id/nine"
android:layout_gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_weight="1"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/zero"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/linearLayout"
android:layout_marginTop="98dp"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true" />
Take the last button in another linearlayout and further add linearlayout in it with weight, try this code....
<?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:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<Button
android:id="#+id/seven"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button
android:id="#+id/eight"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
<Button
android:id="#+id/nine"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_gravity="center_horizontal"
android:layout_weight="1" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:orientation="horizontal"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1">
<Button
android:id="#+id/zero"
android:layout_width="match_parent"
android:layout_height="match_parent" />
</LinearLayout>
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"></LinearLayout>
</LinearLayout>
here is the output
I am trying to create a screen that shows the details of the students. The following is my xml code for that screen.
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
tools:context=".PatientDetails">
<LinearLayout
android:id="#+id/ll1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical"
android:layout_weight="3"
android:background="#color/BackgroundColor">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Details"
android:textColor="#color/white"
android:textSize="30dp"
android:gravity="center"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:id="#+id/ll2"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="vertical"
android:background="#color/white">
<ScrollView
android:layout_width="match_parent"
android:layout_height="wrap_content">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:padding="16dp">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Student Name"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#color/BackgroundColor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/PatientName"
android:text="Joseph"
android:layout_weight="1"
android:textSize="20dp"
android:textColor="#color/BackgroundColor"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Age"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#color/BackgroundColor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/age"
android:text="21"
android:layout_weight="1"
android:textSize="20dp"
android:textColor="#color/BackgroundColor"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:orientation="horizontal"
android:layout_marginTop="16dp">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Sex"
android:textSize="20dp"
android:layout_weight="1"
android:textColor="#color/BackgroundColor"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/Sex"
android:text="Female"
android:layout_weight="1"
android:textSize="20dp"
android:textColor="#color/BackgroundColor"/>
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
The output of the code is as follows:
Can someone tell me how to modify the code so that the values on the right hand side of each row are aligned properly.
Row example:
<LinearLayout
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginTop="16dp"
android:orientation="horizontal">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Student Name"
android:textColor="#color/BackgroundColor"
android:textSize="20dp" />
<TextView
android:id="#+id/PatientName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:text="Joseph"
android:textColor="#color/BackgroundColor"
android:textSize="20dp" />
</LinearLayout>
Remove android:layout_weight="1" from row root. Change android:layout_width="wrap_content" to android:layout_width="0dp"
Sample
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="16dp"
android:orientation="horizontal"
android:weightSum="2">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:layout_weight="1"
android:text="Student Name"
android:textColor="#color/pika_bg"
android:textSize="20dp" />
<TextView
android:id="#+id/PatientName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"
android:paddingLeft="5dp"
android:text="Joseph"
android:textColor="#color/pika_bg"
android:textSize="20dp" />
</LinearLayout>
Here I am added android:weightSum="2"to the parent LinearLayout. So that the child views can get same width. Then we can adjust padding/gravity attributes according to your needs.
I think you use linear layout but linear layout have also one property its called layout_weight i think you should use this.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Test" />
<TextView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:text="Test" />
</LinearLayout>
I am doing Fragment with picker elements. I have two pickers (NumberPicker and TimePicker) in a LinearLayout and I want to align them.
This is my xml code:
<?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" >
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="vertical">
<Switch
android:id="#+id/buscar_instalaciones_horario_fragment_switch1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1" />
<TextView
android:id="#+id/buscar_instalaciones_horario_fragment_tv_subtitulo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:layout_marginBottom="30dp"
android:text="#string/del_14_de_junio_al_31_de_agosto"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_horizontal">
<RadioGroup
android:id="#+id/buscar_instalaciones_horario_fragment_radiogroup"
android:orientation="horizontal"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:id="#+id/buscar_instalaciones_horario_fragment_radiobutton_abierto"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Apertura"
android:checked="true"
android:layout_weight="1"/>
<RadioButton
android:id="#+id/buscar_instalaciones_horario_fragment_radiobutton_cerrado"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Cierre"
android:layout_weight="1"/>
</RadioGroup>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="1"
android:orientation="horizontal">
<NumberPicker
android:id="#+id/buscar_instalaciones_horario_fragment_diasdelasemanaPicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TimePicker android:id="#+id/buscar_instalaciones_horario_fragment_timePicker"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Now this is the screen:
As you can see, the two pickers are not aligned.
Change this Piece of code
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:orientation="horizontal">
<NumberPicker
android:id="#+id/buscar_instalaciones_horario_fragment_diasdelasemanaPicker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1" />
<TimePicker android:id="#+id/buscar_instalaciones_horario_fragment_timePicker"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
edited:
Solved by Adding this line in LinearLayout
android:gravity="center_vertical"
i'm trying to do a school day and i use multiple linearLayout with days and hours.
With the layout_weight i can set the space for every elements inside the single LinearLayout.
But my problem is how can i set the layout_weightfor the LinearLayout because they are set with orientation horizontal and they don't take the entire screen.
It's like a table but i use LinearLayout because i need to create only rows.
This is the xml of the Activity
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent"
android:layout_height="match_parent" android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
tools:context="com.ddz.diarioscolastico.OrarioActivityProva">
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout">
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="2"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Lun"
android:id="#+id/textView2"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Mar"
android:id="#+id/textView" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Mer"
android:id="#+id/textView3" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Gio"
android:id="#+id/textView4" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Ven"
android:id="#+id/textView5" />
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_weight="2"
android:gravity="center"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="Sab"
android:id="#+id/textView6" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_weight="1"
android:layout_below="#+id/linearLayout"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout2">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="1"
android:id="#+id/textView7" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout2"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout3">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="2"
android:id="#+id/textView8" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout3"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout4">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="3"
android:id="#+id/textView9" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout4"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout6">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="4"
android:id="#+id/textView10" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout6"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout5">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="5"
android:id="#+id/textView11" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout5"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout7">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="6"
android:id="#+id/textView12" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout7"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:id="#+id/linearLayout8">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="7"
android:id="#+id/textView13" />
</LinearLayout>
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/linearLayout8"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="8"
android:id="#+id/textView14" />
</LinearLayout>
As you can see if i set the android:layout_height="match_parent" yes all LinearLayout take full screen but only the first is visible, i wanna divide the screen for all.
Using Layout Weight is a little bit tricky task.
Suppose you want to show three buttons horizontally which share equal width in a linear layout. Then the xml code should be like this.
<?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:weightSum="3"
android:orientation="horizontal" >
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="Button 1"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="Button 1"
/>
<Button
android:layout_height="wrap_content"
android:layout_width="0dp"
android:layout_weight="1"
android:text="Button 1"
/>
</LinearLayout>
As you can see,In the parent LinearLayout i used weightSum as 3 and in each child button i set the width to 0dp and weight to 1 and there are three buttons so it will share equal width.
By the way the root parent (RelativeLayout) is not closed in your given layout.
EDIT:2
As you said here is the code divide each LinearLayout equally with layout_weight
<?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:weightSum="3"
android:orientation="vertical" >
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:background="#00FF00"
>
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:background="#FF0000"
>
</LinearLayout>
<LinearLayout
android:layout_height="0dp"
android:layout_weight="1"
android:layout_width="match_parent"
android:background="#0000FF"
>
</LinearLayout>
</LinearLayout>
OUTPUT :
Have you tried to replace your LinearLayout with a TableRow or use a GridLayout ? GridLayout requires API 14 but lower API can be use with the support library.