I'm developing an Android 3.1 Tablet application and asking this here because I haven't found any working answer (or example) in my code.
I have the following piece of code:
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_weight="1" >
<LinearLayout
android:id="#+id/materialsLayout"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<!-- 0 . TÃtulo del fragment -->
<TextView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:layout_weight=".5"
android:gravity="center_horizontal"
android:text="#string/layout_title_quantity"
android:textAppearance="?android:attr/textAppearanceLarge" />
<!-- 1. Texto -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/layout_qty_size_carton"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- 2. Texto -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_gravity="center"
android:orientation="horizontal"
android:weightSum=".45" >
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".1"
android:gravity="right"
android:text="#string/layout_req_po"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".05"
android:text="#string/layout_qty_carton"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/qtyPerCartonTxt"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".05"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".01"
android:gravity="center"
android:text="#string/layout_slash"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".05"
android:text="#string/layout_cartoon_size"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/cartonSizeTxt"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".05"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".01"
android:gravity="center"
android:text="#string/layout_slash"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".03"
android:text="#string/layout_weight"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/cartonWeightTxt"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_gravity="center_vertical"
android:layout_weight=".05"
android:textAppearance="?android:attr/textAppearanceMedium" />
</LinearLayout>
<!-- 3. Titulo tabla -->
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="#string/layout_actual_finding"
android:textAppearance="?android:attr/textAppearanceMedium" />
<!-- 4. Cabecera tabla -->
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_gravity="center"
android:orientation="horizontal"
android:weightSum=".5" >
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".07"
android:gravity="center"
android:text="#string/layout_cartoon_number"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".07"
android:gravity="center"
android:text="#string/layout_actual_qty"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".07"
android:gravity="center"
android:text="#string/layout_actual_size"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".07"
android:gravity="center"
android:text="#string/layout_actual_weight"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Button
android:id="#+id/btnAddNewActPckCtr"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".05"
android:onClick="onAddNewActPckCtrClick"
android:text="#string/btn_add_new" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_gravity="center"
android:orientation="horizontal"
android:weightSum=".5" >
<TextView
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".07"
android:gravity="right"
android:text="#string/layout_result"
android:textAppearance="?android:attr/textAppearanceMedium" />
<RadioGroup
android:id="#+id/rGroupResQTYOnline"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_gravity="right"
android:layout_weight=".07"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rResQTYOnlineYes"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="right"
android:text="#string/layout_yes" />
<RadioButton
android:id="#+id/rResQTYOnlineNo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_gravity="left"
android:text="#string/layout_no" />
</RadioGroup>
<RadioGroup
android:id="#+id/rGroupResSzOnline"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".07"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rResSzOnlineYes"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/layout_yes" />
<RadioButton
android:id="#+id/rResSzOnlineNo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/layout_no" />
</RadioGroup>
<RadioGroup
android:id="#+id/rGroupResWgOnline"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".07"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rResWgOnlineYes"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/layout_yes" />
<RadioButton
android:id="#+id/rResWgOnlineNo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="#string/layout_no" />
</RadioGroup>
<Button
android:id="#+id/btnTakeQtyOnlinePhoto"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight=".07"
android:onClick="onTakePhotoClick"
android:text="#string/btn_take_photo" />
</LinearLayout>
<TextView
android:layout_width="match_parent"
android:layout_height="40dip"
android:layout_gravity="center_horizontal"
android:layout_marginLeft="40dip"
android:layout_marginTop="40dip"
android:layout_weight=".1"
android:gravity="left|center_vertical"
android:text="#string/layout_photos"
android:textAppearance="?android:attr/textAppearanceMedium" />
<Gallery
android:id="#+id/quantityOnlineGallery"
android:layout_width="fill_parent"
android:layout_height="200dip" />
</LinearLayout>
</ScrollView>
I'm trying to center radio buttons inside radiogroup but I don't know how to do it.
I have tried this code:
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center|left"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center|right" />
</RadioGroup>
But it doesn't work.
How can I do it?
It might help to try this:
Align your radio group to center
<RadioGroup
android:id="#+id/rGroupResSzOnline"
android:layout_width="0dip"
android:layout_height="match_parent"
android:layout_weight=".07"
android:gravity="center"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/rResSzOnlineYes"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="Yes" />
<RadioButton
android:id="#+id/rResSzOnlineNo"
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:text="No" />
</RadioGroup>
Have you tried to nest a LinearLayout or RelativeLayout inside the RadioGroup and put the RadioButton within it? I haven't tried myself so I don't know if it works.
Related
image `
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="top"
android:orientation="vertical">
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="15dp"
android:gravity="left"
android:text="Satisfied"
android:textSize="15dp"
android:textStyle="normal" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="150dp"
android:layout_marginTop="10dp"
android:orientation="horizontal">
<com.example.rupertfernandes.itsforyou.progressutil.ProgressIndicator
android:id="#+id/determinate_progress_indicator1"
android:layout_width="150dp"
android:layout_height="150dp"
android:layout_marginLeft="30dp" />
<TextView
android:layout_width="fill_parent"
android:layout_height="150dp"
android:gravity="center"
android:text="Satisfied"
android:textColor="#7CFC00"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
<View
android:layout_width="fill_parent"
android:layout_height="2dp"
android:layout_margin="10dp"
android:background="#ffffff" />
<ScrollView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_weight="1">
<LinearLayout
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical">
<TextView
android:id="#+id/questiontext"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dp"
android:text="Question of the Day"
android:textColor="#7CFC00"
android:textSize="20dp" />
<TextView
android:id="#+id/questiontextOne"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dip"
android:text="Q-1. How are you feeling today ?"
android:textColor="#ff69b4"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/linearLayout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<include
android:id="#+id/cell1"
layout="#layout/radiobutton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/questiontextTwo"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dip"
android:text="Q-3. How is the day going on ?"
android:textColor="#ff69b4"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/linearLayout3"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<include
android:id="#+id/cell1"
layout="#layout/radiobutton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/questiontextThree"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dip"
android:text="Q-4. How is the work going on ?"
android:textColor="#ff69b4"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/linearLayout4"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<include
android:id="#+id/cell1"
layout="#layout/radiobutton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<TextView
android:id="#+id/questiontextFour"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="10dp"
android:padding="10dip"
android:text="Q-5. How is the night going on ?"
android:textColor="#ff69b4"
android:textSize="15dp" />
<LinearLayout
android:id="#+id/linearLayout5"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentLeft="true">
<include
android:id="#+id/cell1"
layout="#layout/radiobutton"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</LinearLayout>
<Button
android:id="#+id/btnsubmitwellbeing"
android:layout_width="fill_parent"
android:background="#7CFC00"
android:layout_height="wrap_content"
android:layout_margin="10dp"
android:text="Submit"
android:textAllCaps="false"
android:textColor="#ffffff"
android:textSize="25dp"
android:textStyle="bold" />
</LinearLayout>
</ScrollView>
</LinearLayout>
</LinearLayout>
below is the include code:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="3dp"
android:weightSum="1" >
<RadioGroup
android:id="#+id/radioGroupWell"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<RadioButton
android:id="#+id/extremely_unsatisfied"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:gravity="center"
android:onClick="extremely_unsatisfied"
android:text="Extremely Unsatisfied"
android:drawableTop="#drawable/user_icon"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
<RadioButton
android:id="#+id/unsatisfied"
android:layout_width="0dp"
android:button="#null"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:drawableTop="#drawable/user_icon"
android:gravity="center"
android:onClick="unsatisfied"
android:text="Unsatisfied"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
<RadioButton
android:id="#+id/neutral"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:button="#null"
android:drawableTop="#drawable/user_icon"
android:gravity="center"
android:text="Neutral"
android:onClick="neutral"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
<RadioButton
android:id="#+id/satisfied"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:drawableTop="#drawable/user_icon"
android:gravity="center"
android:button="#null"
android:onClick="satisfied"
android:text="Satisfied"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
<RadioButton
android:id="#+id/extremly_satisfied"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight=".2"
android:drawableTop="#drawable/user_icon"
android:gravity="center"
android:onClick="extremly unsatisfied"
android:text="Extremely Satisfied"
android:button="#null"
android:textAppearance="?android:attr/textAppearanceSmall"
android:textColor="#000000" >
</RadioButton>
</RadioGroup>
</LinearLayout>
`I have attached a file.
It has 5 radiobuttons in one row..and there are 5 such rows..the radiobuttons are inside a scroll view.
kindly help with xml file and the code as to how to check the radio buttons and also on click of submit the value in the circular progress bar should increase based on the user input in the radio buttonsthe image is as shown
You can't attach files here.
RadioButtons have an OnCheckChangedLister that does what you'd expect. Or you can call isChecked() to poll the value.
I am trying to place a radio group with 3 radio buttons inside a linear layout. My aim is to choose only one RadioButton inside the RadioGroup but, it is giving me an error that there are multiple root tags. Can someone figure out how to solve this?
file.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="ok"
android:id="#+id/textemail"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
<TextView
android:id="#+id/textView1"
android:layout_below="#+id/textemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="To:"
/>
<TextView
android:id="#+id/TextTo"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="khushi"/>
<TextView
android:id="#+id/textView2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Comment:"
/>
<TextView
android:id="#+id/TextS3"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your comment"
/>
<TextView
android:id="#+id/textView4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="email us "
android:textAppearance="?android:attr/textAppearanceLarge" />
<EditText
android:id="#+id/editText"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:inputType="textMultiLine"
android:lines="10" />
<Button
android:id="#+id/button"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Send"
android:textStyle="italic"/>
</LinearLayout>
You immediately close your radiogroup:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"/>
This should be:
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"> // Note that there is no forward slash at the end
And you are not closing the RadioGroup:
</RadioButton> <-- This should be </RadioGroup>
Your RadioButton (views) should be children of the RadioGroup(view). By closing your RadioGroup using /> you declare the RadioButton(s) and the RadioGroup as children of the LinearLayout.
The Following should work.
<?xml version="1.0" encoding="utf-8"?>
<Linearlayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="#+id/linearLayout1"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="hello"
android:id="#+id/textview"/>
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioButton>
</RadioGroup>
<TextView
android:id="#+id/textViewllol"
android:layout_below="#+id/textemail"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="hi:"
/>
<TextView
android:id="#+id/Texme"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text=""
/>
<TextView
android:id="#+id/textView3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="comment:"
/>
<TextView
android:id="#+id/Text2"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="your comments"
/>
<TextView
android:id="#+id/textView45"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok"
/>
<EditText
android:id="#+id/editTextMessage"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="top"
android:lines="10" />
<Button
android:id="#+id/button4785"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="send"
/>
</LinearLayout>
Change below -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent"/>
to
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
One of your Text is not in correct format change it as below -
<TextView
android:id="#+id/textView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok:"
/>
to
<TextView
android:id="#+id/textView"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="ok:"
/>
One more error -
change below -
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
to
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content">
You have one </Radiobutton> tag above </Radiogroup> that shouldn't be here. Just remove it to have :
<RadioGroup
android:layout_width="match_parent"
android:layout_height="match_parent">
<RadioButton
android:id="#+id/one"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="one" />
<RadioButton
android:id="#+id/two"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="two"
/>
<RadioButton
android:id="#+id/three"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="three" />
</RadioGroup>
How do I center align Radio button inside LinearLayout
For the TextViews:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1.4">
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:padding="2dp"
android:textColor="#000000"
android:text="Often"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:textColor="#000000"
android:paddingRight="5dp"
android:paddingLeft="2dp"
android:text="Sometimes"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:textColor="#000000"
android:padding="2dp"
android:text="Rarely"
/>
<TextView
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:textColor="#000000"
android:text="Never"
/>
</LinearLayout>
For the RadioButtons:
<LinearLayout
android:layout_width="0dp"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:layout_weight="1.4">
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:padding="2dp"
/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.3"
android:paddingRight="5dp"
android:paddingLeft="2dp"
android:layout_gravity="center"
/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
android:padding="2dp"
/>
<RadioButton
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_weight="0.2"
/>
</LinearLayout>
This is still it looks like :
May I know where i am doing mistake, I already tried with layout_gravity = "center" and gravity = "center"
How can i align it to Center, where i have to make change ?
Try with this one:
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_gravity="center">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_gravity="center"
android:paddingLeft="2dp"
android:paddingRight="5dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"/>
</LinearLayout>
If I understand correctly what you want to do..i suggest you the below layout..
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:gravity="center_horizontal"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="horizontal">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"
android:gravity="center_vertical"/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1"/>
</LinearLayout>
</LinearLayout>
Check this It will make both checkbox and textview in center.
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Often"
android:textColor="#000000"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Often"
android:textColor="#000000"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Often"
android:textColor="#000000"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
android:text="Often"
android:textColor="#000000"
/>
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:padding="2dp"
/>
</LinearLayout>
Try with this one. It will work for no of buttons you want.
Surely its works:
<HorizontalScrollView
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Often"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Sometimes"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Rarely"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Never"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Often"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Sometimes"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Rarely"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp" />
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:orientation="vertical" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp"
android:text="Never"
android:textColor="#000000" />
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:gravity="center"
android:padding="2dp" />
</LinearLayout>
</LinearLayout>
</HorizontalScrollView>
Use the following line in the radio button's block which you want to align at the center:
android:layout_centerInParent="true"
I am experiencing some strange behaviour with my layouts. As you can see from the screenshot below (of the layout in eclipse) the 'register' button appears just fine at the bottom of the screen.
Before
However, if you now take a look at the following screenshot taken on my phone (HTC ONE X) whilst debugging, the button is completely cut off with plenty of space.
After
The code for the register page is as follows (where the button is contained within the relative layout)
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:gravity="center"
android:text="Register"
android:textSize="18sp" />
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="25dp"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Title:" />
<EditText
android:id="#+id/txtTitle"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="First Name:" />
<EditText
android:id="#+id/txtFirstName"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Surname:" />
<EditText
android:id="#+id/txtSurname"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Email:" />
<EditText
android:id="#+id/txtEmail"
android:layout_width="0dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Age:" />
<EditText
android:id="#+id/txtAge"
android:layout_width="10dp"
android:layout_height="wrap_content"
android:layout_marginRight="20dp"
android:layout_weight="0.75"
android:ems="10"
android:text="" />
</LinearLayout>
<TableLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:stretchColumns="*"
android:weightSum="4" >
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<TextView
android:id="#+id/txtGender"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Gender" />
<TextView
android:id="#+id/txtTypeOfUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginLeft="20dp"
android:layout_weight="0.25"
android:text="Type of User" />
</TableRow>
<TableRow
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="1" >
<RadioGroup
android:id="#+id/radioSex"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioMale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="Male" />
<RadioButton
android:id="#+id/radioFemale"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Female" />
</RadioGroup>
<RadioGroup
android:id="#+id/radioTypeOfUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioUser"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:checked="true"
android:text="User" />
<RadioButton
android:id="#+id/radioDoctor"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Doctor" />
</RadioGroup>
</TableRow>
</TableLayout>
<RelativeLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<Button
android:id="#+id/image"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_alignParentBottom="true"
android:layout_alignParentRight="true"
android:layout_marginBottom="20dp"
android:layout_marginRight="20dp"
android:text="Register" />
</RelativeLayout>
</LinearLayout>
Your TableLayout has layout_height set to fill_parent, change it to wrap_content.
<TableLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginTop="10dp"
android:orientation="vertical"
android:stretchColumns="*"
android:weightSum="4" >
Hi i have an application, where i want to use scroll option in liner layout. Please help me i am stuck.
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
>
<AnalogClock android:id="#+id/clock1" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<ImageButton android:id="#+id/rssbtn" android:src="#drawable/rss"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<ProgressBar android:id="#+id/progress"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<RadioGroup android:id="#+id/widget1" android:layout_width="wrap_content"
android:layout_height="wrap_content" xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical">
<RadioButton android:id="#+id/widget2"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Plain" android:checked="false" android:layout_gravity="left"
android:layout_weight="0">
</RadioButton>
<RadioButton android:id="#+id/widget3"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Serif" android:checked="true" android:layout_gravity="left"
android:layout_weight="0" android:typeface="serif">
</RadioButton>
<RadioButton android:id="#+id/widget25"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:text="Bold" android:checked="false" android:layout_weight="0"
android:layout_gravity="left" android:textStyle="bold">
</RadioButton>
</RadioGroup>
<Spinner android:id="#+id/widget1" android:layout_width="fill_parent"
android:layout_height="wrap_content" android:drawSelectorOnTop="false" />
<TimePicker android:id="#+id/widget3" android:layout_width="wrap_content"
android:layout_height="wrap_content" />
<CheckBox android:id="#+id/plain_cb" android:text="Plain"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<CheckBox android:id="#+id/serif_cb" android:text="Serif"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:typeface="serif" />
<CheckBox android:id="#+id/bold_cb" android:text="Bold"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" />
<CheckBox android:id="#+id/italic_cb" android:text="Italic"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="italic" />
<Button android:id="#+id/button1" android:text="Label"
android:layout_width="fill_parent" android:layout_height="fill_parent" />
<Button android:id="#+id/button2" android:text="Label"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:typeface="serif" />
<Button android:id="#+id/button3" android:text="Label"
android:layout_width="fill_parent" android:layout_height="fill_parent"
android:textStyle="italic" />
<DatePicker android:id="#+id/datepicker"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<EditText android:id="#+id/edittext1" android:text="EditText 1"
android:layout_width="wrap_content" android:layout_height="wrap_content" />
<EditText android:id="#+id/button2" android:text="(206)555-1212"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:typeface="serif" android:phoneNumber="true" />
<EditText android:id="#+id/password" android:text="SuperSecret"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:textStyle="bold" android:password="true" />
</LinearLayout>
Wrap your LinearLayout in a ScrollView at the top of the file
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="wrap_content" android:layout_height="fill_parent">
<LinearLayout
android:layout_width="wrap_content" android:layout_height="fill_parent"
android:orientation="vertical"
android:scrollbars="vertical"
android:scrollbarAlwaysDrawVerticalTrack="true"
>
.....
</LinearLayout>
</ScrollView>