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"**
>
Related
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 an app that shows a Radio Group with four Radio Buttons whose test is set dynamically. I am no able to get the whole text on a single line.
It gets wrapped on two lines, or truncated at the end. It seems like there is a vertical edge, and text cannot go over it.
My layout is
android:paddingRight="#dimen/activity_horizontal_margin"
android:paddingTop="#dimen/activity_vertical_margin"
tools:context="vds.quizmanager.QuizManagerActivity" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="Domanda:" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_below="#+id/textView2"
android:layout_marginTop="24dp"
android:layout_toLeftOf="#+id/button2" >
<RadioButton
android:id="#+id/radio0"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minWidth="#dimen/activity_vertical_margin" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RadioGroup>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup1"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:text="Domanda" />
</RelativeLayout>
OK then you can try this code:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/RelativeLayout1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical" >
<TextView
android:id="#+id/textView1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginBottom="41dp"
android:text="Domanda:" />
<TextView
android:id="#+id/textView2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_centerHorizontal="true"
android:layout_marginTop="19dp"
android:text="sdfsgdshfdgsasRFAGRESTDGHFSAFAWhtjygukjtyhergwrqTQETWRYJETRHEWRQEJTUKRYJTRHEAWRWetjyurrutjretwrtjyeukyriu" />
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_below="#+id/textView2"
android:layout_alignParentLeft="true"
android:layout_alignParentRight="true"
android:layout_marginTop="24dp"
android:layout_toLeftOf="#+id/button2" >
<RadioButton
android:id="#+id/radio0"
android:text="Domandaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:minWidth="#dimen/activity_vertical_margin" />
<RadioButton
android:id="#+id/radio1"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio2"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<RadioButton
android:id="#+id/radio3"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
</RadioGroup>
<Button
android:id="#+id/button2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/radioGroup1"
android:layout_centerHorizontal="true"
android:layout_marginTop="90dp"
android:text="Domanda" />
</RelativeLayout>
This is result:
I have a layout that has multiple radio buttons in different rows ( two columns of radio buttons separated by table rows) and when i select one of them,the previous selected doesn't get deselected.I keep selecting all the other's and none gets deselected . This only happens because of the rows as the straight layout works just fine .what am i doing wrong ?
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="17dp"
android:layout_marginStart="17dp"
android:orientation="vertical"/>
<TableRow>
<RadioButton
android:id="#+id/miliToCentimeters"
android:layout_width="258dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:checked="true"
android:clickable="false"
android:text="#string/milimetersToCentimeters"
android:textSize="13sp" />
<RadioButton
android:id="#+id/inchesToFoothesToFoot"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/inchesToFoot"
android:textSize="13sp" />
</TableRow>
<TableRow>
<RadioButton
android:id="#+id/centiToMeters"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:text="#string/centemetersToMeters"
android:textSize="13sp" />
<RadioButton
android:id="#+id/inchesToYardsesToYards"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:text="#string/inchesToYards"
android:textSize="13sp" />
</TableRow>
<TableRow>
<RadioButton
android:id="#+id/miliToMetersiToMeters"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:text="#string/milimetersToMeters"
android:textSize="13sp" />
<RadioButton
android:id="#+id/feetToYardsetToYards"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:text="#string/feetToYards"
android:textSize="13sp" />
</TableRow>
<TableRow>
<RadioButton
android:id="#+id/metersToKiloersToKilo"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:text="#string/metersToKilometers"
android:textSize="13sp" />
<RadioButton
android:id="#+id/feetToMilesetToMiles"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:text="#string/feetToMiles"
android:textSize="13sp"/>
</TableRow>
<TableRow>
<RadioButton
android:id="#+id/yardsToMilesdsToMiles"
android:layout_width="255dp"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:text="#string/yardsToMiles"
android:textSize="13sp" />
</TableRow>
</RadioGroup>
Use the below code for selecting single radio button at a time. You should close the radio group only after all the radio button declared inside of the radio group.
<RadioGroup
android:id="#+id/radioGroup1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_below="#+id/textView1"
android:layout_centerHorizontal="true"
android:layout_marginLeft="17dp"
android:layout_marginStart="17dp"
android:orientation="vertical">
<RadioButton
android:id="#+id/miliToCentimeters"
android:layout_width="258dp"
android:layout_height="wrap_content"
android:layout_marginTop="0dp"
android:checked="true"
android:clickable="false"
android:text="#string/milimetersToCentimeters"
android:textSize="13sp" />
<RadioButton
android:id="#+id/inchesToFoothesToFoot"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/inchesToFoot"
android:textSize="13sp" />
<RadioButton
android:id="#+id/centiToMeters"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:text="#string/centemetersToMeters"
android:textSize="13sp" />
<RadioButton
android:id="#+id/inchesToYardsesToYards"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:text="#string/inchesToYards"
android:textSize="13sp" />
<RadioButton
android:id="#+id/miliToMetersiToMeters"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:text="#string/milimetersToMeters"
android:textSize="13sp" />
<RadioButton
android:id="#+id/feetToYardsetToYards"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:text="#string/feetToYards"
android:textSize="13sp" />
<RadioButton
android:id="#+id/metersToKiloersToKilo"
android:layout_width="255dp"
android:layout_height="wrap_content"
android:layout_marginTop="-5dp"
android:text="#string/metersToKilometers"
android:textSize="13sp" />
<RadioButton
android:id="#+id/feetToMilesetToMiles"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:text="#string/feetToMiles"
android:textSize="13sp"/>
<RadioButton
android:id="#+id/yardsToMilesdsToMiles"
android:layout_width="255dp"
android:layout_height="match_parent"
android:layout_marginTop="-5dp"
android:text="#string/yardsToMiles"
android:textSize="13sp" />
</RadioGroup>
I have a relative layout with scrollview. In My relative layout i have few image buttons and radio group when i select the radio option the bottom image view android:id="#+id/sol_btn
goes up.
Why its goes up? what mistake in my layout? And in my manifest also i have used this
android:windowSoftInputMode="stateHidden|adjustPan"
My layout code here:
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".Quesans">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/que_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:text="TextView" />
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/que_txt"
android:layout_marginTop="15dp"
android:layout_marginBottom="40dp"
android:layout_below="#+id/que_txt"/>
<RadioGroup
android:id="#+id/rdgroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/image"
android:orientation="vertical" >
<RadioButton
android:id="#+id/RB1"
android:text=""/>
<RadioButton
android:id="#+id/RB2"
android:text=""/>
<RadioButton
android:id="#+id/RB3"
android:text=""/>
<RadioButton
android:id="#+id/RB4"
android:text=""/>
</RadioGroup>
<TextView
android:id="#+id/rdtxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rdgroup"
android:layout_marginTop="40dp"
android:text="Nothing is picked"
android:textColor="#0000FF"/>
<ImageView
android:id="#+id/nxt_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/rdtxt"
android:layout_marginRight="22dp"
android:layout_marginTop="40dp"
android:src="#drawable/next_pressed" />
<ImageView
android:id="#+id/focusarea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/nxt_btn"
android:layout_below="#+id/nxt_btn"
android:layout_marginRight="1dp"
android:layout_marginTop="10dp"
android:src="#drawable/focusarea_pressed" />
<ImageView
android:id="#+id/app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="140dp"
android:layout_marginBottom="0dp"
android:src="#drawable/newapps" />
<ImageView
android:id="#+id/prv_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/image"
android:layout_alignTop="#+id/nxt_btn"
android:src="#drawable/previous_pressed" />
<ImageView
android:id="#+id/sol_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/prv_btn"
android:layout_below="#+id/prv_btn"
android:layout_marginTop="10dp"
android:layout_marginLeft="1dp"
android:src="#drawable/solution_pressed" />
</RelativeLayout>
</ScrollView>
I have changed images to default. Edit xml file and try this,it will work fine.
<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" >
<ScrollView
android:layout_width="match_parent"
android:layout_height="match_parent" >
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="match_parent" >
<TextView
android:id="#+id/que_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:text="TextView" />
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/que_txt"
android:layout_below="#+id/que_txt"
android:layout_marginBottom="40dp"
android:layout_marginTop="15dp"
android:background="#drawable/ic_launcher" />
<RadioGroup
android:id="#+id/rdgroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/image"
android:orientation="vertical" >
<RadioButton
android:id="#+id/RB1"
android:text="" />
<RadioButton
android:id="#+id/RB2"
android:text="" />
<RadioButton
android:id="#+id/RB3"
android:text="" />
<RadioButton
android:id="#+id/RB4"
android:text="" />
</RadioGroup>
<TextView
android:id="#+id/rdtxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rdgroup"
android:layout_marginTop="40dp"
android:text="Nothing is picked"
android:textColor="#0000FF" />
<ImageView
android:id="#+id/focusarea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/nxt_btn"
android:layout_below="#+id/nxt_btn"
android:layout_marginRight="1dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/sol_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/prv_btn"
android:layout_below="#+id/prv_btn"
android:layout_marginLeft="1dp"
android:layout_alignParentBottom="true"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/prv_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/image"
android:layout_below="#+id/rdtxt"
android:layout_marginTop="18dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/nxt_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_alignTop="#+id/prv_btn"
android:layout_marginRight="18dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_centerHorizontal="true"
android:baselineAlignBottom="true"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</ScrollView>
Here is screenshot:
Your Solution Button(#+id/sol_btn) having Margin 10 dp to the previous button(#+id/prv_btn).,
So For the First question since the previous button will not be in the view your Solution button is going to the top of the view.
So Make the visibility of the previous button from View.Gone to View.Invisible.
Your problem will be solved:-
<?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:layout_width="fill_parent"
android:layout_height="fill_parent"
tools:context=".Quesans">
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<TextView
android:id="#+id/que_txt"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginLeft="10dp"
android:layout_marginTop="25dp"
android:text="TextView" />
<ImageView
android:id="#+id/image"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/que_txt"
android:layout_marginTop="15dp"
android:layout_marginBottom="40dp"
android:layout_below="#+id/que_txt"/>
<RadioGroup
android:id="#+id/rdgroup"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/image"
android:orientation="vertical" >
<RadioButton
android:id="#+id/RB1"
android:text=""/>
<RadioButton
android:id="#+id/RB2"
android:text=""/>
<RadioButton
android:id="#+id/RB3"
android:text=""/>
<RadioButton
android:id="#+id/RB4"
android:text=""/>
</RadioGroup>
<TextView
android:id="#+id/rdtxt"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/rdgroup"
android:layout_marginTop="40dp"
android:text="Nothing is picked"
android:textColor="#0000FF"/>
<ImageView
android:id="#+id/nxt_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/rdtxt"
android:layout_marginRight="22dp"
android:layout_marginTop="40dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/focusarea"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignRight="#+id/nxt_btn"
android:layout_below="#+id/nxt_btn"
android:layout_marginRight="1dp"
android:layout_marginTop="10dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/app"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentBottom="true"
android:layout_marginLeft="140dp"
android:layout_marginBottom="0dp"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/prv_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/image"
android:layout_alignTop="#+id/nxt_btn"
android:src="#drawable/ic_launcher" />
<ImageView
android:id="#+id/sol_btn"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/prv_btn"
android:layout_below="#+id/prv_btn"
android:layout_marginTop="10dp"
android:layout_marginLeft="1dp"
android:src="#drawable/ic_launcher" />
</RelativeLayout>
</ScrollView>
Try setting android:focusable=false on your RadioGroup
Remove android:windowSoftInputMode="stateHidden|adjustPan" from your menifest. I have done like this.. It is not go up.
i am doing one application in android but i have one problem in layout file
i am doing by viewFliper
here is 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" >
<TextView
android:id="#+id/Quesiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:text="#string/Question"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroupOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Quesiontext"
android:layout_marginTop="30dp" >
<RadioButton
android:id="#+id/optionOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/option1" />
<RadioButton
android:id="#+id/optionTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option2" />
<RadioButton
android:id="#+id/optionthree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option3" />
<RadioButton
android:id="#+id/optionFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option4" />
</RadioGroup>
<TextView
android:id="#+id/corrertView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/radioGroupOptions"
android:layout_marginRight="48dp"
android:text="#string/correct" />
<Button
android:id="#+id/btnNext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignLeft="#+id/corrertView"
android:layout_below="#+id/corrertView"
android:layout_marginTop="42dp"
android:text="#string/Next"
android:textSize="16sp" />
<Button
android:id="#+id/Btnpervious"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignBaseline="#+id/btnNext"
android:layout_alignBottom="#+id/btnNext"
android:layout_alignParentLeft="true"
android:text="#string/Pervious"
android:textSize="16sp" />
<RelativeLayout
android:id="#+id/layout"
android:layout_width="match_parent"
android:layout_height="match_parent">
<ViewFlipper
android:id="#+id/ViewFlipper01"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<TextView
android:id="#+id/Quesiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_alignParentTop="true"
android:layout_marginTop="44dp"
android:text="#string/Question"
android:textSize="18sp" />
<RadioGroup
android:id="#+id/radioGroupOptions"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentLeft="true"
android:layout_below="#+id/Quesiontext"
android:layout_marginTop="30dp" >
<RadioButton
android:id="#+id/optionOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="false"
android:text="#string/option1" />
<RadioButton
android:id="#+id/optionTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option2" />
<RadioButton
android:id="#+id/optionthree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option3" />
<RadioButton
android:id="#+id/optionFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/option4" />
</RadioGroup>
<TextView
android:id="#+id/corrertView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentRight="true"
android:layout_below="#+id/radioGroupOptions"
android:layout_marginRight="48dp"
android:text="#string/correct" />
</ViewFlipper>
</RelativeLayout>
</RelativeLayout>
i didnt get it that how i put another button into ViewFliper ..its confusion and generating error...
You haven't closed your ViewFlipper with </ViewFlipper>
Could this be what you are looking for,
android:id="#+id/layout"
You missed a "+" symbol while creating a id.