I cannot get the layout below such that the two side-by-side radioGroups centralize. At the moment, they are a little to the right. As soon as I try to adjust anything (either by clicking and dragging or by modifying the xml, all hell breaks loose and either the entire display vanishes or it gets corrupted.
I want to say, basically:
Center the top textfield and the Pass button.
Center the boundary between the two radioGroups.
Align the left hand side of the Double button to the left hand side of the left hand radio group.
Align the right hand side of the Redouble button to the right hand side of the right hand radioGRoup.
Align the "Small text" text field in the center, not to the left.
Align the Next button in the center.
Any pointers would be much appreciated. Code and image follow.
<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.example.owner.bidmate.WhatBid"
android:background="#29ff3a">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="very long text so it widens the field"
android:id="#+id/bidtitle"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pass"
android:id="#+id/passButton"
android:checked="false"
android:textOff="Pass"
android:textOn="Pass"
android:background="#080dff"
android:textColor="#fafff8"
android:layout_below="#+id/bidtitle"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"/>
<RadioGroup
android:layout_width="120dp"
android:layout_height="220dp"
android:id="#+id/radioGroup"
android:background="#befffc"
android:gravity="center_vertical"
android:layout_below="#+id/passButton"
android:layout_toLeftOf="#+id/radioGroup2"
android:layout_toStartOf="#+id/radioGroup2"
android:layout_marginBottom="10dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One"
android:id="#+id/radioButton"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Two"
android:id="#+id/radioButton2"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three"
android:id="#+id/radioButton3"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Four"
android:id="#+id/radioButton4"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Five"
android:id="#+id/radioButton5"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Six"
android:id="#+id/radioButton6"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Seven"
android:id="#+id/radioButton7"
android:checked="false"/>
</RadioGroup>
<RadioGroup
android:layout_width="120dp"
android:layout_height="220dp"
android:id="#+id/radioGroup2"
android:background="#c7fffd"
android:gravity="center_vertical"
android:layout_marginRight="0dp"
android:layout_marginEnd="22dp"
android:layout_alignTop="#+id/radioGroup"
android:layout_alignRight="#+id/redoubleButton"
android:layout_alignEnd="#+id/redoubleButton"
android:layout_marginBottom="10dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Club"
android:id="#+id/radioButton8"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Diamond"
android:id="#+id/radioButton9"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heart"
android:id="#+id/radioButton10"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spade"
android:id="#+id/radioButton11"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Trump"
android:id="#+id/radioButton12"
android:checked="false"/>
</RadioGroup>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Double"
android:id="#+id/doubleButton"
android:checked="false"
android:textOff="Double"
android:textOn="Double"
android:background="#ff151a"
android:textColor="#fefffd"
android:layout_below="#+id/radioGroup"
android:layout_alignLeft="#+id/radioGroup"
android:layout_alignStart="#+id/radioGroup"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Redouble"
android:id="#+id/redoubleButton"
android:checked="false"
android:textOff="Redouble"
android:textOn="Redouble"
android:background="#ff1521"
android:textColor="#fbfffb"
android:layout_toRightOf="#+id/wbnextbutton"
android:layout_below="#+id/radioGroup2"
/>
<TextView
android:layout_width="200dp"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:id="#+id/textView"
android:layout_below="#+id/doubleButton"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:paddingTop="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/wbnextbutton"
android:layout_alignParentBottom="true"
android:layout_alignRight="#+id/passButton"
android:layout_alignEnd="#+id/passButton"/>
</RelativeLayout>
<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.example.owner.bidmate.WhatBid"
android:background="#29ff3a">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="very long text so it widens the field"
android:id="#+id/bidtitle"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Pass"
android:id="#+id/passButton"
android:checked="false"
android:textOff="Pass"
android:textOn="Pass"
android:background="#080dff"
android:textColor="#fafff8"
android:layout_below="#+id/bidtitle"
android:layout_centerHorizontal="true"
android:layout_marginTop="15dp"
android:layout_marginBottom="10dp"/>
<RadioGroup
android:layout_width="120dp"
android:layout_height="220dp"
android:id="#+id/radioGroup"
android:background="#befffc"
android:gravity="center_vertical"
android:layout_below="#+id/passButton"
android:layout_toLeftOf="#+id/temp"
android:layout_marginBottom="10dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="One"
android:id="#+id/radioButton"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Two"
android:id="#+id/radioButton2"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Three"
android:id="#+id/radioButton3"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Four"
android:id="#+id/radioButton4"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Five"
android:id="#+id/radioButton5"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Six"
android:id="#+id/radioButton6"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Seven"
android:id="#+id/radioButton7"
android:checked="false"/>
</RadioGroup>
<View android:layout_below="#+id/passButton" android:layout_centerHorizontal="true" android:layout_width="0dp" android:layout_height="1dp" android:id="#+id/temp"></View>
<RadioGroup
android:layout_width="120dp"
android:layout_height="220dp"
android:id="#+id/radioGroup2"
android:background="#c7fffd"
android:gravity="center_vertical"
android:layout_marginRight="0dp"
android:layout_marginEnd="22dp"
android:layout_below="#+id/passButton"
android:layout_toRightOf="#+id/temp"
android:layout_marginBottom="10dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Club"
android:id="#+id/radioButton8"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Diamond"
android:id="#+id/radioButton9"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Heart"
android:id="#+id/radioButton10"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Spade"
android:id="#+id/radioButton11"
android:checked="false"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="No Trump"
android:id="#+id/radioButton12"
android:checked="false"/>
</RadioGroup>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Double"
android:id="#+id/doubleButton"
android:checked="false"
android:textOff="Double"
android:textOn="Double"
android:background="#ff151a"
android:textColor="#fefffd"
android:layout_below="#+id/radioGroup"
android:layout_alignLeft="#+id/radioGroup"
android:layout_alignStart="#+id/radioGroup"/>
<ToggleButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Redouble"
android:id="#+id/redoubleButton"
android:checked="false"
android:textOff="Redouble"
android:textOn="Redouble"
android:background="#ff1521"
android:textColor="#fbfffb"
android:layout_toRightOf="#+id/wbnextbutton"
android:layout_alignRight="#+id/radioGroup2"
android:layout_below="#+id/radioGroup2"
/>
<TextView
android:layout_width="wrap_content"
android:layout_height="50dp"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="Small Text"
android:gravity="center"
android:id="#+id/textView"
android:layout_below="#+id/doubleButton"
android:layout_centerHorizontal="true"
android:layout_alignParentEnd="false"
android:paddingTop="20dp"/>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Next"
android:id="#+id/wbnextbutton"
android:layout_centerHorizontal="true"
android:layout_alignParentBottom="true"/>
</RelativeLayout>
Related
I was trying to find a way to scroll my Relative Layout while I'm in designer in Intellij, since I can't see all the elements I want and position them right. I researched and read numerous threads and the advice I saw most was "wrap the layout you want to scroll in ScrollView", which I did, but that didn't help me. I still can't see all of my widgets and when I put them near the end of the screen, they either shrink or get positioned below - where I can't see them and manage them. I'm new to all this, so I guess I must be doing something wrong.
I apologize in advance if the answer to this question already exists, I couldn't find it
Here's my XML :
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ScrollView02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:fillViewport="true"
android:nestedScrollingEnabled="true"
android:scrollIndicators="right"
tools:scrollY="150px" android:addStatesFromChildren="true" android:isScrollContainer="true"
android:scrollbarAlwaysDrawHorizontalTrack="false" android:scrollY="300dp">
<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="wrap_content"
android:paddingLeft="#dimen/activity_horizontal_margin"
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
android:paddingBottom="#dimen/activity_vertical_margin"
>
<ImageButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/imageButton3"
android:layout_alignParentTop="true" android:layout_alignParentStart="false"
android:layout_alignParentEnd="true" android:background="#drawable/abc_ic_menu_overflow_material"
android:clickable="true"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="TITLE"
android:id="#+id/textView7" android:layout_below="#+id/imageButton3"
android:layout_centerHorizontal="true" android:textSize="25dp" android:textStyle="bold"/>
<Spinner
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/spinner"
android:layout_marginLeft="20dp" android:layout_marginRight="20dp"
android:layout_above="#+id/textView9" android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"/>
<SeekBar
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:id="#+id/seekBar"
android:layout_alignBottom="#+id/weight_button" android:layout_toEndOf="#+id/weight_button"
android:layout_marginBottom="12dp"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="First"
android:id="#+id/textView9"
android:layout_above="#+id/textView10" android:layout_alignStart="#+id/spinner"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="< >"
android:id="#+id/textView10"
android:textStyle="bold"
android:textSize="20dp"
android:layout_above="#+id/seekBar" android:layout_toStartOf="#+id/imageButton3"/>
<Button
android:layout_width="50dp"
android:layout_height="50dp"
android:id="#+id/weight_button"
android:text="80"
android:allowUndo="true"
android:background="#drawable/round_button_weight"
android:layout_marginLeft="5dp" android:textColor="#android:color/white"
android:layout_above="#+id/textView11" android:layout_alignStart="#+id/textView9"
android:layout_marginBottom="17dp"/>
<LinearLayout android:orientation="horizontal" android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/weight_button"
android:layout_alignEnd="#+id/imageButton3" android:id="#+id/linearLayout2"
android:layout_marginTop="10dp" android:layout_alignLeft="#+id/weight_button">
</LinearLayout>
<TextView android:layout_width="match_parent" android:layout_height="1dp" android:id="#+id/textView11"
android:background="#555252" android:layout_weight="1" android:layout_gravity="center_vertical"
android:layout_alignParentStart="true" android:layout_marginBottom="10dp"
android:layout_above="#+id/textView12"/>
<SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#+id/seekBar2"
android:layout_centerVertical="true" android:layout_toEndOf="#+id/button"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second"
android:id="#+id/textView12"
android:layout_above="#+id/button" android:layout_alignStart="#+id/textView9"
android:layout_marginBottom="5dp" android:layout_marginTop="10dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="< >"
android:id="#+id/textView13" android:textStyle="bold" android:textSize="20dp"
android:layout_below="#+id/textView12" android:layout_alignEnd="#+id/spinner"/>
<Button android:layout_width="50dp" android:layout_height="50dp" android:id="#+id/button" android:text="175"
android:allowUndo="true" android:background="#drawable/round_button_height"
android:textColor="#android:color/white"
android:layout_centerVertical="true" android:layout_toStartOf="#+id/seekBar"/>
<TextView android:layout_width="match_parent" android:layout_height="1dp" android:id="#+id/textView14"
android:background="#555252" android:layout_weight="1" android:layout_gravity="center_vertical"
android:layout_below="#+id/button" android:layout_alignLeft="#+id/textView11"
android:layout_marginTop="10dp" android:layout_marginBottom="5dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Third"
android:id="#+id/textView15"
android:layout_below="#+id/textView14" android:layout_alignStart="#+id/button2"
android:layout_marginBottom="5dp" android:layout_marginTop="10dp"/>
<Button android:layout_width="50dp" android:layout_height="50dp" android:id="#+id/button2" android:text="24"
android:allowUndo="true" android:background="#drawable/round_button_height"
android:textColor="#android:color/white"
android:layout_alignTop="#+id/textView16" android:layout_toStartOf="#+id/seekBar3"
android:layout_marginBottom="20dp"/>
<SeekBar android:layout_width="match_parent" android:layout_height="wrap_content" android:id="#+id/seekBar3"
android:layout_alignBottom="#+id/button2" android:layout_alignStart="#+id/seekBar2"
android:layout_marginBottom="12dp"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="< >"
android:id="#+id/textView16" android:textStyle="bold" android:textSize="20dp"
android:layout_below="#+id/textView15"
android:layout_alignRight="#+id/textView10" android:layout_alignLeft="#+id/textView10"/>
<TextView android:layout_width="match_parent" android:layout_height="1dp" android:id="#+id/textView17"
android:background="#555252" android:layout_weight="1" android:layout_gravity="center_vertical"
android:layout_below="#+id/button2"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0-6"
android:id="#+id/radioButton1"
android:layout_marginTop="37dp" android:checked="false"
android:layout_below="#+id/textView17" android:layout_alignEnd="#+id/textView9"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="6-18"
android:id="#+id/radioButton2"
android:checked="false"
android:layout_alignTop="#+id/radioButton3" android:layout_centerHorizontal="true"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text=">18"
android:id="#+id/radioButton3"
android:checked="false"
android:layout_alignTop="#+id/radioButton1" android:layout_alignEnd="#+id/textView16"
android:layout_marginEnd="26dp"/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="Title1"
android:id="#+id/textView18"
android:textStyle="bold"
android:textSize="15dp" android:layout_above="#+id/radioButton2" android:layout_alignParentStart="false"
android:padding="10dp" android:textAllCaps="true" android:textColor="#android:color/white"
android:background="#3b3c50" android:layout_marginTop="20dp" android:layout_marginBottom="10dp"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content"
android:text="Title2" android:id="#+id/textView19"
android:textStyle="bold"
android:textSize="15dp" android:layout_below="#+id/radioButton1"
android:layout_alignStart="#+id/textView18" android:layout_marginTop="10dp"
android:layout_marginBottom="10dp" android:padding="10dp" android:textAllCaps="true"
android:textColor="#android:color/white" android:background="#3b3c50"/>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1"
android:id="#+id/radioButton" android:checked="false"
android:layout_below="#+id/textView19" android:layout_alignStart="#+id/radioButton1"/>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2"
android:id="#+id/radioButton4" android:checked="false"
android:layout_below="#+id/textView19" android:layout_alignEnd="#+id/textView7"/>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3"
android:id="#+id/radioButton5" android:checked="false"
android:layout_alignTop="#+id/radioButton4" android:layout_alignEnd="#+id/textView13"/>
<TextView android:layout_width="match_parent" android:layout_height="wrap_content" android:text="Title 3"
android:id="#+id/textView20" android:textStyle="bold" android:textSize="15dp"
android:layout_below="#+id/radioButton" android:layout_alignStart="#+id/textView19"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp"
android:textColor="#android:color/white" android:background="#3b3c50" android:textAllCaps="true"
android:padding="10dp"/>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="1"
android:id="#+id/radioButton6" android:checked="false"
android:layout_below="#+id/textView20" android:layout_alignStart="#+id/radioButton"/>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="2"
android:id="#+id/radioButton7" android:checked="false"
android:layout_alignTop="#+id/radioButton6" android:layout_alignStart="#+id/radioButton4"/>
<RadioButton android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="3"
android:id="#+id/radioButton8" android:checked="false"
android:layout_alignTop="#+id/radioButton7" android:layout_alignStart="#+id/radioButton5"/>
<TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Title4"
android:id="#+id/textView21" android:textStyle="bold" android:textSize="15dp"
android:layout_below="#+id/radioButton8" android:layout_alignStart="#+id/textView20"
android:layout_marginTop="10dp" android:layout_marginBottom="10dp"/>
</RelativeLayout>
</ScrollView>
You can add LinearLayout under ScrollView and then put RelativeLayout under LinearLayout.
Try this i have edited your layout file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="#+id/ScrollView02"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:addStatesFromChildren="true"
android:fillViewport="true"
android:isScrollContainer="true"
android:nestedScrollingEnabled="true"
android:scrollIndicators="right"
android:scrollbarAlwaysDrawHorizontalTrack="false"
tools:scrollY="150px">
<RelativeLayout
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">
<ImageButton
android:id="#+id/imageButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentEnd="true"
android:layout_alignParentTop="true"
android:background="#drawable/abc_ic_menu_overflow_material"
android:clickable="true" />
<TextView
android:id="#+id/textView7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/imageButton3"
android:layout_centerHorizontal="true"
android:text="TITLE"
android:textSize="25dp"
android:textStyle="bold" />
<Spinner
android:id="#+id/spinner"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView9"
android:layout_centerHorizontal="true"
android:layout_marginBottom="20dp"
android:layout_marginLeft="20dp"
android:layout_marginRight="20dp" />
<SeekBar
android:id="#+id/seekBar"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/weight_button"
android:layout_marginBottom="12dp"
android:layout_toRightOf="#+id/weight_button"
android:layout_toEndOf="#+id/weight_button" />
<TextView
android:id="#+id/textView9"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView10"
android:layout_alignLeft="#+id/spinner"
android:layout_alignStart="#+id/spinner"
android:text="First" />
<TextView
android:id="#+id/textView10"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/seekBar"
android:layout_toLeftOf="#+id/imageButton3"
android:layout_toStartOf="#+id/imageButton3"
android:text="< >"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="#+id/weight_button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_above="#+id/textView11"
android:layout_alignLeft="#+id/textView9"
android:layout_alignStart="#+id/textView9"
android:layout_marginBottom="17dp"
android:layout_marginLeft="5dp"
android:allowUndo="true"
android:background="#drawable/round_button_weight"
android:text="80"
android:textColor="#android:color/white" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/imageButton3"
android:layout_alignRight="#+id/imageButton3"
android:layout_alignLeft="#+id/weight_button"
android:layout_below="#+id/weight_button"
android:layout_marginTop="10dp"
android:orientation="horizontal"></LinearLayout>
<TextView
android:id="#+id/textView11"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_above="#+id/textView12"
android:layout_alignParentStart="true"
android:layout_alignParentLeft="true"
android:layout_gravity="center_vertical"
android:layout_marginBottom="10dp"
android:layout_weight="1"
android:background="#555252" />
<SeekBar
android:id="#+id/seekBar2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:layout_toEndOf="#+id/button"
android:layout_toRightOf="#+id/button" />
<TextView
android:id="#+id/textView12"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/button"
android:layout_alignStart="#+id/textView9"
android:layout_alignLeft="#+id/textView9"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:text="Second" />
<TextView
android:id="#+id/textView13"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/spinner"
android:layout_alignRight="#+id/spinner"
android:layout_below="#+id/textView12"
android:text="< >"
android:textSize="20dp"
android:textStyle="bold" />
<Button
android:id="#+id/button"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_centerVertical="true"
android:layout_toStartOf="#+id/seekBar"
android:layout_toLeftOf="#+id/seekBar"
android:allowUndo="true"
android:background="#drawable/round_button_height"
android:text="175"
android:textColor="#android:color/white" />
<TextView
android:id="#+id/textView14"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_alignLeft="#+id/textView11"
android:layout_below="#+id/button"
android:layout_gravity="center_vertical"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:layout_weight="1"
android:background="#555252" />
<TextView
android:id="#+id/textView15"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/button2"
android:layout_alignLeft="#+id/button2"
android:layout_below="#+id/textView14"
android:layout_marginBottom="5dp"
android:layout_marginTop="10dp"
android:text="Third" />
<Button
android:id="#+id/button2"
android:layout_width="50dp"
android:layout_height="50dp"
android:layout_alignTop="#+id/textView16"
android:layout_marginBottom="20dp"
android:layout_toStartOf="#+id/seekBar3"
android:layout_toLeftOf="#+id/seekBar3"
android:allowUndo="true"
android:background="#drawable/round_button_height"
android:text="24"
android:textColor="#android:color/white" />
<SeekBar
android:id="#+id/seekBar3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/button2"
android:layout_alignStart="#+id/seekBar2"
android:layout_alignLeft="#+id/seekBar2"
android:layout_marginBottom="12dp" />
<TextView
android:id="#+id/textView16"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView10"
android:layout_alignRight="#+id/textView10"
android:layout_below="#+id/textView15"
android:text="< >"
android:textSize="20dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView17"
android:layout_width="match_parent"
android:layout_height="1dp"
android:layout_below="#+id/button2"
android:layout_gravity="center_vertical"
android:layout_weight="1"
android:background="#555252" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView9"
android:layout_alignRight="#+id/textView9"
android:layout_below="#+id/textView17"
android:layout_marginTop="37dp"
android:checked="false"
android:text="0-6" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/radioButton3"
android:layout_centerHorizontal="true"
android:checked="false"
android:text="6-18" />
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView16"
android:layout_alignRight="#+id/textView16"
android:layout_alignTop="#+id/radioButton1"
android:layout_marginEnd="26dp"
android:layout_marginRight="26dp"
android:checked="false"
android:text=">18" />
<TextView
android:id="#+id/textView18"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_above="#+id/radioButton2"
android:layout_alignParentStart="false"
android:layout_alignParentLeft="false"
android:layout_marginBottom="10dp"
android:layout_marginTop="20dp"
android:background="#3b3c50"
android:padding="10dp"
android:text="Title1"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
<TextView
android:id="#+id/textView19"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/textView18"
android:layout_alignLeft="#+id/textView18"
android:layout_below="#+id/radioButton1"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#3b3c50"
android:padding="10dp"
android:text="Title2"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/radioButton"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/radioButton1"
android:layout_alignLeft="#+id/radioButton1"
android:layout_below="#+id/textView19"
android:checked="false"
android:text="1" />
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView7"
android:layout_alignRight="#+id/textView7"
android:layout_below="#+id/textView19"
android:checked="false"
android:text="2" />
<RadioButton
android:id="#+id/radioButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignEnd="#+id/textView13"
android:layout_alignRight="#+id/textView13"
android:layout_alignTop="#+id/radioButton4"
android:checked="false"
android:text="3" />
<TextView
android:id="#+id/textView20"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/textView19"
android:layout_alignLeft="#+id/textView19"
android:layout_below="#+id/radioButton"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:background="#3b3c50"
android:padding="10dp"
android:text="Title 3"
android:textAllCaps="true"
android:textColor="#android:color/white"
android:textSize="15dp"
android:textStyle="bold" />
<RadioButton
android:id="#+id/radioButton6"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/radioButton"
android:layout_alignLeft="#+id/radioButton"
android:layout_below="#+id/textView20"
android:checked="false"
android:text="1" />
<RadioButton
android:id="#+id/radioButton7"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/radioButton4"
android:layout_alignLeft="#+id/radioButton4"
android:layout_alignTop="#+id/radioButton6"
android:checked="false"
android:text="2" />
<RadioButton
android:id="#+id/radioButton8"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/radioButton5"
android:layout_alignLeft="#+id/radioButton5"
android:layout_alignTop="#+id/radioButton7"
android:checked="false"
android:text="3" />
<TextView
android:id="#+id/textView21"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignStart="#+id/textView20"
android:layout_alignLeft="#+id/textView20"
android:layout_below="#+id/radioButton8"
android:layout_marginBottom="10dp"
android:layout_marginTop="10dp"
android:text="Title4"
android:textSize="15dp"
android:textStyle="bold" />
</RelativeLayout>
Thank you for your suggestions, but neither of them did help. After I updated IntelliJ to 3.x version, it worked, without changing the code.
I have three radio groups each with two button inside of them. As you can see from this picture: http://imgur.com/JQJ0a7A [1] ,the buttons are all lined up nicely in android studio. However, when I run the app in the VM I end up with this: http://imgur.com/nKdth41 [2].
Any ideas why this is occurring? Thanks in advance for any help.
xml code:
<?xml version="1.0" encoding="utf-8"?>
<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: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="onerepmax.reversepyramid.RPworkout">
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/workoutButton"
android:id="#+id/button"
android:layout_alignParentTop="true"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:width="175dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/warmupButton"
android:id="#+id/button3"
android:width="175dp"
android:layout_alignBottom="#+id/button"
android:layout_toRightOf="#+id/button"
android:layout_toEndOf="#+id/button" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/liftText"
android:layout_marginTop="50dp"
android:layout_below="#+id/button"
android:layout_centerHorizontal="true" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="#+id/weightText1"
android:layout_marginRight="36dp"
android:layout_marginEnd="36dp"
android:layout_alignTop="#+id/repText1"
android:layout_toLeftOf="#+id/repText1"
android:layout_toStartOf="#+id/repText1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="#+id/repText1"
android:layout_marginTop="66dp"
android:layout_below="#+id/liftText"
android:layout_alignLeft="#+id/liftText"
android:layout_alignStart="#+id/liftText"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="#+id/weightText2"
android:layout_alignTop="#+id/weightText1"
android:layout_marginTop="70dp"
android:layout_alignLeft="#+id/weightText3"
android:layout_alignStart="#+id/weightText3" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="#+id/repText2"
android:layout_alignTop="#+id/repText1"
android:layout_alignLeft="#+id/repText1"
android:layout_alignStart="#+id/repText1"
android:layout_marginTop="70dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="xxx lbs"
android:id="#+id/weightText3"
android:layout_alignTop="#+id/weightText2"
android:layout_marginTop="70dp"
android:layout_alignLeft="#+id/weightText1"
android:layout_alignStart="#+id/weightText1" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall"
android:text="XX reps"
android:id="#+id/repText3"
android:layout_centerVertical="true"
android:layout_alignLeft="#+id/repText1"
android:layout_alignStart="#+id/repText1"
android:layout_alignTop="#+id/repText2"
android:layout_marginTop="70dp" />
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/nextButton"
android:id="#+id/nextButton"
android:layout_marginBottom="39dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="#+id/button3"
android:layout_alignEnd="#+id/button3"
android:layout_above="#+id/weightText3"
android:orientation="horizontal"
android:layout_toRightOf="#+id/nextButton"
android:layout_toEndOf="#+id/nextButton"
android:layout_below="#+id/liftText"
android:id="#+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton2"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="59dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton"
android:checked="false"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="59dp"
android:buttonTint="#d32323"/>
</RadioGroup>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_alignRight="#+id/radioGroup"
android:layout_alignEnd="#+id/radioGroup"
android:layout_below="#+id/weightText1"
android:layout_alignBottom="#+id/weightText3"
android:orientation="horizontal"
android:layout_toEndOf="#+id/button"
android:layout_toRightOf="#+id/button">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton3"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="45dp"
android:layout_marginLeft="45dp"
android:layout_marginStart="45dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton4"
android:checked="false"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="45dp"
android:buttonTint="#d32323"/>
</RadioGroup>
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_alignRight="#+id/radioGroup"
android:layout_alignEnd="#+id/radioGroup"
android:layout_below="#+id/repText2"
android:layout_above="#+id/nextButton">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton5"
android:checked="false"
android:buttonTint="#2ebb39"
android:layout_marginTop="45dp"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton6"
android:checked="false"
android:layout_marginRight="37dp"
android:layout_marginEnd="37dp"
android:layout_marginLeft="29dp"
android:layout_marginStart="29dp"
android:layout_marginTop="45dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>
This should solve your alignment issue, also there is no need to have to label text views, instead do:
<?xml version="1.0" encoding="utf-8"?>
<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: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="onerepmax.reversepyramid.RPworkout">
<!-- Even spaced buttons above -->
<LinearLayout
android:id="#+id/btn_wrapper"
android:layout_alignParentTop="true"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content">
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Workout"
android:id="#+id/button"
android:layout_weight="1"/>
<Button
android:layout_width="0dp"
android:layout_height="wrap_content"
android:text="Warmup"
android:id="#+id/button3"
android:layout_weight="1"/>
</LinearLayout>
<!-- Centered Text -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="Large Text"
android:id="#+id/liftText"
android:layout_marginTop="50dp"
android:layout_below="#+id/btn_wrapper"
android:layout_centerHorizontal="true" />
<!-- Centered Radio Group with Label 1 -->
<RelativeLayout
android:id="#+id/set_1"
android:layout_below="#+id/liftText"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight">
<TextView
android:id="#+id/txt_lbs_1"
android:text="xxx lbs xx reps"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_toRightOf="#+id/txt_lbs_1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_centerVertical="true"
android:id="#+id/radioGroup">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton2"
android:layout_marginLeft="16dp"
android:checked="false"
android:buttonTint="#2ebb39"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButton"
android:checked="false"
android:layout_marginLeft="16dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>
<!-- Centered Radio Group with Label 2 -->
<RelativeLayout
android:id="#+id/set_2"
android:layout_below="#+id/set_1"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight">
<TextView
android:id="#+id/txt_lbs_2"
android:text="xxx lbs xx reps"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_toRightOf="#+id/txt_lbs_2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:id="#+id/radioGroup2">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButtonPassTwo"
android:layout_marginLeft="16dp"
android:checked="false"
android:buttonTint="#2ebb39"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButtonFailTwo"
android:checked="false"
android:layout_marginLeft="16dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>
<!-- Centered Radio Group with Label 3 -->
<RelativeLayout
android:id="#+id/set_3"
android:layout_below="#+id/set_2"
android:gravity="center_horizontal"
android:layout_width="match_parent"
android:layout_height="?listPreferredItemHeight">
<TextView
android:id="#+id/txt_lbs_3"
android:text="xxx lbs xx reps"
android:layout_centerVertical="true"
android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<RadioGroup
android:layout_toRightOf="#+id/txt_lbs_3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerVertical="true"
android:orientation="horizontal"
android:id="#+id/radioGroup3">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButtonPassThree"
android:layout_marginLeft="16dp"
android:checked="false"
android:buttonTint="#2ebb39"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioButtonFailThree"
android:checked="false"
android:layout_marginLeft="16dp"
android:buttonTint="#d32323"/>
</RadioGroup>
</RelativeLayout>
<Button
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Workout"
android:id="#+id/nextButton"
android:layout_marginBottom="39dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true" />
</RelativeLayout>
And when you want to set something like "200 lbs 10 reps" for the TextView with txt_lbs_1
do:
TextView mTextViewLbs1 = (TextView) findViewById(R.id.txt_lbs_1);
mTextViewLbs1.setText(String.format("%1$d lbs %2$d reps", 200, 3));
This yields:
Good luck and hope this points you in a better direction.
Happy Coding!
I have the following XML code:
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:id="#+id/et1"
android:autoText="false"
android:text="40"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/radioGroup"
android:width="20dp"
android:layout_toStartOf="#+id/radioGroup2"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView" />
I would like to set a specific width or a max width would also do the trick (not working either). The text field is going from the vertical centre to the far right and I would like it to position from vertical centre to 20p to the right.
When I set max_width or width it doesn't seem to take any effect. It makes no difference what I put in.
Any idea why? Thanks for an answers.
Below is a screen shot of the activity followed by all the XML Code:
<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:background="#drawable/bg"
android:paddingBottom="#dimen/activity_vertical_margin" tools:context=".MainActivity">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioGroup"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:paddingTop="30dp"
android:paddingLeft="5dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rB2"
android:id="#+id/radioButton2"
android:checked="true"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/rB1"
android:id="#+id/radioButton1"
android:checked="false"
android:textColor="#000000"
android:layout_below="#+id/radioGroup"
android:layout_alignRight="#+id/radioGroup"
android:layout_alignEnd="#+id/radioGroup" />
</RadioGroup>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:id="#+id/et1"
android:autoText="false"
android:text="40"
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/radioGroup"
android:width="20dp"
android:layout_toStartOf="#+id/radioGroup2"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="#string/tV1"
android:id="#+id/textView"
android:textSize="13dp"
android:textColor="#000000"
android:layout_below="#+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_marginTop="112dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="#string/result"
android:id="#+id/textView2"
android:layout_marginBottom="45dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/explan"
android:id="#+id/textView3"
android:textColor="#000000"
android:paddingLeft="20dp"
android:layout_below="#+id/et1"
android:layout_centerHorizontal="true"
android:layout_marginTop="73dp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioGroup2"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:paddingTop="30dp"
android:paddingRight="5dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5% bonus"
android:id="#+id/radioButton3"
android:checked="false"
android:textColor="#000000"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/radioButton4"
android:layout_alignStart="#+id/radioButton4" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10% bonus"
android:id="#+id/radioButton4"
android:layout_gravity="right"
android:checked="true"
android:textColor="#000000"
android:layout_alignTop="#+id/radioButton1"
android:layout_toRightOf="#+id/textView2"
android:layout_toEndOf="#+id/textView2" />
</RadioGroup>
</RelativeLayout>
Change android:layout_width="wrap_content" to match_parent
or you can also manually set width such as "50dp" or "100dp"
Please see below code may it help you, othervise please give us your full xml code.
<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">
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioGroup"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/textView"
android:layout_alignStart="#+id/textView"
android:paddingTop="30dp"
android:paddingLeft="5dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rB2"
android:id="#+id/radioButton2"
android:checked="true"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="rB1"
android:id="#+id/radioButton1"
android:checked="false"
android:textColor="#000000"
android:layout_below="#+id/radioGroup"
android:layout_alignRight="#+id/radioGroup"
android:layout_alignEnd="#+id/radioGroup" />
</RadioGroup>
<LinearLayout android:id="#+id/mylinearforedittext"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView"
android:layout_alignParentLeft="true"
android:layout_alignParentStart="true"
android:orientation="horizontal"
android:weightSum="2"
android:layout_marginTop="10dp"
>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:id="#+id/et11"
android:autoText="false"
android:text="40"
android:ems="10"
android:width="20dp"
android:layout_weight="1"
android:visibility="invisible"
android:focusable="false"
android:focusableInTouchMode="false" />
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:id="#+id/et1"
android:autoText="false"
android:text="40"
android:ems="10"
android:width="20dp"
android:layout_weight="1" />
</LinearLayout>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium"
android:text="tV1"
android:id="#+id/textView"
android:textSize="13dp"
android:textColor="#000000"
android:layout_below="#+id/radioGroup"
android:layout_centerHorizontal="true"
android:layout_marginTop="112dp" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceLarge"
android:text="result"
android:id="#+id/textView2"
android:layout_marginBottom="45dp"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:textColor="#000000" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="explan"
android:id="#+id/textView3"
android:textColor="#000000"
android:paddingLeft="20dp"
android:layout_below="#+id/mylinearforedittext"
android:layout_centerHorizontal="true"
android:layout_marginTop="73dp" />
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/radioGroup2"
android:layout_alignParentTop="true"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView"
android:paddingTop="30dp"
android:paddingRight="5dp">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="5% bonus"
android:id="#+id/radioButton3"
android:checked="false"
android:textColor="#000000"
android:layout_alignParentTop="true"
android:layout_alignLeft="#+id/radioButton4"
android:layout_alignStart="#+id/radioButton4" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="10% bonus"
android:id="#+id/radioButton4"
android:layout_gravity="right"
android:checked="true"
android:textColor="#000000"
android:layout_alignTop="#+id/radioButton1"
android:layout_toRightOf="#+id/textView2"
android:layout_toEndOf="#+id/textView2" />
</RadioGroup>
You're using : android:layout_toStartOf="#+id/radioGroup2" in the EditText which means that your text views starts from where your radioGroup2 starts which is from the middle of the screen.
You'll need to remove this line.
Have you undertaken these instructions?
fill_parent/match_parent
android:gravity /layoutgravity
<EditText
android:text="40"
android:layout_width="match_parent" //imp :can use fill_parent too
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:id="#+id/et1"
android:autoText="false"
android:layout_margin="150dp" //use whichever dp you want
android:layout_centerVertical="true"
android:layout_toRightOf="#+id/radioGroup"
android:width="20dp"
android:layout_toStartOf="#+id/radioGroup2"
android:layout_alignRight="#+id/textView"
android:layout_alignEnd="#+id/textView" />
Hope it Helps
I'm Developing an android app in which the login activity contains radio button for the field department and years of experience. And I've designed my login activity in Relative layout.So now i wanted to RadioGroup the radiobuttons without changing the alignment. Please Help me !
Thanks in Advance !
`
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentTop="true"
android:layout_centerHorizontal="true"
android:text="#string/reg_view"
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/editText2"
android:layout_below="#+id/textView1"
android:layout_marginTop="59dp"
android:ems="10"
android:hint="#string/firstname"
android:inputType="textPersonName"
android:text="#string/edit_name" />
<EditText
android:id="#+id/editText2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView2"
android:layout_below="#+id/editText1"
android:ems="10"
android:hint="#string/lastname"
android:inputType="textPersonName"
android:text="#string/edit_name" />
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/editText1"
android:layout_alignLeft="#+id/editText1"
android:layout_marginBottom="35dp"
android:text="#string/name_view"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="#+id/radioButton2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/textView4"
android:layout_alignRight="#+id/textView1"
android:text="#string/teamleader_radio" />
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_below="#+id/textView2"
android:checked="true"
android:text="#string/manager_radio" />
<Button
android:id="#+id/button1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_toRightOf="#+id/textView5"
android:text="#string/Registration_proceed" />
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioButton1"
android:layout_centerHorizontal="true"
android:text="#string/years_view"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioButton
android:id="#+id/radioButton3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/textView4"
android:layout_below="#+id/textView4"
android:text="#string/years_check" />
<RadioButton
android:id="#+id/radioButton4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/radioButton3"
android:layout_alignBottom="#+id/radioButton3"
android:layout_centerHorizontal="true"
android:text="#string/years1_check" />
<RadioButton
android:id="#+id/radioButton5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/radioButton4"
android:layout_alignBottom="#+id/radioButton4"
android:layout_alignParentRight="true"
android:text="#string/years3_check" />
<TextView
android:id="#+id/textView5"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioButton3"
android:layout_toLeftOf="#+id/radioButton4"
android:text="#string/dept_view"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/radioButton1"
android:layout_below="#+id/editText2"
android:text="#string/desig_view"
android:textAppearance="?android:attr/textAppearanceMedium" />
`
You can use the <RadioGroup> to group the Radio buttons like this;
<RadioGroup
android:id="#+id/radioGroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/Red"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/red"
android:textColor="#android:color/holo_red_dark"
android:onClick="onRadioButtonClicked" />
<RadioButton
android:id="#+id/Green"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/green"
android:textColor="#android:color/holo_green_dark"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:id="#+id/Blue"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/blue"
android:textColor="#android:color/holo_blue_dark"
android:onClick="onRadioButtonClicked"/>
</RadioGroup>
Below is my Relative layout..i am trying to place the radio buttons above the edittext
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:background="#FFFFFF" >
<ImageView
android:id="#+id/fbreplycancel"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignParentTop="true"
android:src="#drawable/fbcancel" />
<RelativeLayout
android:id="#+id/relativeLayout1"
android:layout_width="80dp"
android:layout_height="250dp"
android:layout_alignParentRight="true"
android:layout_below="#+id/fbcancel" >
<Spinner
android:id="#+id/replyspinner"
android:layout_width="50dp"
android:layout_height="30dp"
android:layout_alignLeft="#+id/fbshare"
android:layout_alignRight="#+id/fbshare"
android:layout_below="#+id/fbshare"
android:layout_marginTop="16dp"
android:drawSelectorOnTop="true"
android:entries="#array/fbcommentlist"
android:visibility="gone" />
<Button
android:id="#+id/fbshare"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:background="#drawable/fbbuttons"
android:text="#string/share" />
<ImageView
android:id="#+id/fbpeople"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_above="#+id/fbshare"
android:layout_centerHorizontal="true"
android:layout_marginBottom="19dp"
android:background="#drawable/people2"
android:drawSelectorOnTop="true"
android:paddingTop="20dp" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_centerVertical="true"
android:text="RadioButton" />
</RelativeLayout>
<View
android:layout_width="250dp"
android:layout_height="0.7dip"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_below="#+id/imageView1"
android:background="#3b5998" />
<ImageView
android:id="#+id/imageView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/fbcancel"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:paddingRight="2dp"
android:src="#drawable/askabud" />
<TextView
android:id="#+id/fbcommentpostedby"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/fbedittext"
android:layout_alignRight="#+id/fbcommentdisplay"
android:layout_below="#+id/imageView1"
android:layout_marginTop="15dp"
android:textColor="#000000" />
<TextView
android:id="#+id/fbcommentdisplay"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/fbedittext"
android:layout_below="#+id/fbcommentpostedby"
android:layout_toLeftOf="#+id/relativeLayout1"
android:textColor="#000000" />
<TextView
android:id="#+id/fbtextview"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBottom="#+id/imageView1"
android:layout_toLeftOf="#+id/fbreplycancel"
android:layout_toRightOf="#+id/imageView1"
android:text="#string/replyrecommend"
android:textSize="18sp"
android:textColor="#000000"/>
<TextView
android:id="#+id/fbplacename"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/fbcommentdisplay"
android:layout_alignRight="#+id/fbcommentdisplay"
android:layout_below="#+id/fbcommentdisplay"
android:textColor="#000000" />
<EditText
android:id="#+id/fbedittext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/fbplacename"
android:layout_marginLeft="19dp"
android:layout_marginTop="45dp"
android:layout_toLeftOf="#+id/relativeLayout1"
android:background="#drawable/roundcorners"
android:ems="10"
android:hint="#string/fbhint"
android:lines="6"
android:scrollHorizontally="true"
android:textSize="14sp"
android:windowSoftInputMode="stateHidden" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/fbplacename" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="30dp"
android:layout_height="30dp"
android:checked="true"
android:text="1"
/>
</RadioGroup>
<RadioGroup
android:id="#+id/radioGroup2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignTop="#+id/radioGroup1"
android:layout_toLeftOf="#+id/relativeLayout1" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="26dp"
android:layout_height="wrap_content"
android:checked="true"
android:text="3" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="RadioButton" />
</RadioGroup>
<RadioButton
android:id="#+id/radio1"
android:layout_width="30dp"
android:layout_height="30dp"
android:layout_alignTop="#+id/radioGroup2"
android:layout_toLeftOf="#+id/radioGroup2"
android:text="2" />
</RelativeLayout>
Iam facing a hard time to arrange them horizontally.Any help is appreciated.
To place a radiogroup (or any other view) above other just do:
android:layout_above="#+id/view_below"
To change the orientation just set:
android:orientation="horizontal"
And to give equal width to items make use of layout_weight:
<RadioGroup
android:id="#+id/radio_group"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_above="#+id/view_below" >
<RadioButton
android:id="#+id/radio1"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:checked="true"
android:text="First" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="0dp"
android:layout_weight="1"
android:layout_height="wrap_content"
android:text="Second" />
</RadioGroup>
You can use table layout instead of relative layout. Insert row into into table layout and place radio buttons inside table row..
For equal spacing follow following procedure
<TableRow
android:id="#+id/tableRow2"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginTop="50dp" >
<RadioButton
android:id="#+id/button2"
android:layout_width="5dp"
android:layout_height="60dp"
android:layout_weight="1"
android:text="#string/btnReject"
android:onClick="onCallRejectButton" />
<RadioButton
android:id="#+id/button1"
android:layout_width="5dp"
android:layout_height="60dp"
android:layout_weight="1
android:onClick="onCallAcceptButton"
android:text="#string/btnAccept" />
</TableRow>
android:orientation="horizontal" just do this. Type the orientation horizontal property to the radiogroup tag
<RadioGroup
android:id="#+id/radio"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Male"
android:checked="true" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
You just need to put Radio Group orientation to horizontal.
<RadioGroup
android:id="#+id/radio_group_forgot_password"
android:layout_width="match_parent"
android:layout_height="wrap_content"
**android:orientation="horizontal"**
>