RadioGroup with radiobuttons inside a relative android layout - android

I want to create a simple layout like the following:
(o) Radio button A
(o) Radio button B [textedit]
[x] checkbox
For that I've created the following layout.xml:
<RadioGroup
android:layout_above="#+id/RadioButton_Count"
android:id="#+id/RadioGroup01"
android:layout_height="wrap_content"
android:layout_width="fill_parent">
<RadioButton
android:layout_height="wrap_content"
android:id="#+id/RadioButton_A"
android:text="Play forever"
android:checked="true"
android:layout_width="fill_parent"
android:textSize="20sp">
</RadioButton>
<RelativeLayout
android:id="#+id/RelativeLayout01"
android:layout_width="wrap_content"
android:layout_height="wrap_content">
<RadioButton
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/RadioButton_B"
android:text="Count:"
android:textSize="20sp">
</RadioButton>
<EditText
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/EditText_NumCount"
android:inputType="number"
android:layout_toRightOf="#+id/RadioButton_B"
android:width="70sp" >
</EditText>
<CheckBox
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:id="#+id/CheckBox_StopCount"
android:text="Stop"
android:layout_below="#+id/RadioButton_B"
android:textSize="18sp">
</CheckBox>
</RelativeLayout>
</RadioGroup>
It looks right, but the problem is that the radiobuttons doesn't connect between each other, i mean that they can be both on in the same moment.
I think it's because even if they're hanging from the same the second one is inside another layout :\
Does anyone have some idea how could I make this kind of layout (Mainly the [textedit] just right the RadioButton B), getting working also the radiobuttons?
Thank you very much

You simply can't do it. I was also trying to do something similar and got stuck.
"RadioButtons have to be direct children of RadioGroup."
https://code.google.com/p/android/issues/detail?id=1214

The first thing to try is to close your RadioGroup right after you close the last RadioButton instead of at the end. A better solution is to use a RelativeLayout as the overall container. Next add your RadioGroup and both buttons and close the group. Add the other elements relative to the rest of the layout.

Related

how to add a button on right of a textview

i want to add a button on right of a textview and if textview grows,button would be still there.i used FrameLayout or RelativeLayout but they didn't work,please help me.
a layout like this image http://www.8pic.ir/images/97364937705465965477.png
Try with LinearLayout by giving orientation as horizontal.
<LinearLayout
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal" >
<TextView
android:id="#+id/textView_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="your text"
/>
<Button
android:id="#+id/button_id"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight=".5"
android:text="button" />
</LinearLayout>
It is not possible directly and it is not good practice also for Android development. Though if it is your requirement, then you can count lines and number of character in last line at run time and decide the position of your button by using either frame or relative layout.

How do you put text above or below a RadioButton in Android

I was trying to figure out how to fit a set of radiobuttons into the available space. The problem was that I was using a horizontal layout and the text beside each button made the whole radiogroup too big to fit. It looked ugly. What I wanted to do was to put the text for each radio button above the radiobutton.
This answer is actually WRONG. I discovered, with some additional testing, that putting the LinearLayouts and TextFields in the RadioGroup gives you a non-functional RadioGroup. The only way I could restore proper functioning was to remove the TextFields and LinearLayouts. I had to become a little more creative in how I arranged things in order to get stuff to fit.
It just goes to show that when you think you're being clever, you usually aren't. :)
------- Wrong Answer --------
I discovered that I could put layouts within the radiogroup, so I used a vertically oriented LinearLayout for each of the radiobuttons within the radiogroup. I included a textfield above each button and put the label text in there. I removed the label text from the button itself, and voila, I had a radiogroup with the labels for the buttons above the buttons.
Here's an example:
<RadioGroup
android:id="#+id/bar_display_filter_radiogroup"
android:layout_width="0dip"
android:layout_height="wrap_content"
android:layout_weight="1"
android:layout_gravity="center_horizontal"
android:checkedButton="#+id/bar_filter_all"
android:orientation="horizontal" >
<LinearLayout
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
android:text="#string/bar_radiobutton_all_text"
style="#style/RadioButton"
/>
<RadioButton
android:id="#+id/bar_filter_all"
style="#style/RadioButton"
android:onClick="onFilterClick"
/>
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
style="#style/RadioButton"
android:text="#string/bar_radiobutton_enroute_text" />
<RadioButton
android:id="#+id/bar_filter_enroute"
style="#style/RadioButton"
android:onClick="onFilterClick" />
</LinearLayout>
<LinearLayout
android:layout_weight="1"
android:gravity="center_horizontal"
android:orientation="vertical" >
<TextView
style="#style/RadioButton"
android:text="#string/bar_radiobutton_delivered_text"/>
<RadioButton
android:id="#+id/bar_filter_delivered"
style="#style/RadioButton"
android:onClick="onFilterClick"
/>
</LinearLayout>
</RadioGroup>
I hope this proves useful for someone else encountering the same problem.

Recreating CheckedTextView's Functionality

I'd like to recreate the CheckedTextView's functionality using my own custom views so I can have two TextViews on the left with a CheckBox on the right, centered vertically between the two TextViews. I have the Layout working for it, which I will include below. I also have it so that when you click on the outer LinearLayout (LinearLayout1) it will pass that click to the checkbox. The only thing that I can't figure out is when you press down on a checkbox it briefly highlights the checkbox (in yellow on my device) before marking it checked. I'd like to have it do the same if you touch anywhere on the outer LinearLayout, but I don't know where I'd need to hook in to make that happen.
Here is my layout.xml
<LinearLayout
android:orientation="horizontal"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:id="#+id/LinearLayout1">
<LinearLayout
android:orientation="vertical"
android:layout_height="wrap_content"
android:layout_width="0dip"
android:layout_weight="1"
android:id="#+id/LinearLayout2">
<TextView
android:id="#+id/FieldValueTextView"
android:text="Value"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceMedium" />
<TextView
android:id="#+id/FieldLabelTextView"
android:text="Label"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:textAppearance="?android:attr/textAppearanceSmall" />
</LinearLayout>
<CheckBox
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:layout_toRightOf="#id/LinearLayout2"
android:id="#+id/CheckBox"
android:gravity="center_vertical" />
</LinearLayout>
Thanks,
Dan
The problem I was experiencing was solved by putting the following android:focusable="false" on the CheckBox and the two TextViews so that when the ListView is clicked, it gets the focus, not the inner views.
Hope that helps someone else.

Radio button spaces of leftDrawable & rightDrawable

I have a RadioGroup with radio buttons:
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:id="#+id/radioGroup1"
>
<RadioButton
android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:checked="true"
android:text="AAA"
android:button="#null"
android:drawableLeft="#drawable/flag_icon"
android:drawableRight="#android:drawable/btn_radio"
android:drawablePadding="60dp"
android:id="#+id/radio2"/>
<RadioButton.../>
</RadioGroup>
As you see above, for the RadioButton I defined the following attributes:
...
android:button="#null"
android:drawableLeft="#drawable/flag_icon"
android:drawableRight="#android:drawable/btn_radio"
...
So that the radio button is located on the right side of the radio button text. The left side of button text is a flag icon.
In order to have spaces between button text and flag icon and button icon, I use android:drawablePadding="60dp" to space them.
However, with above code, the 60dp padding space is applied to both left drawable (flag icon) and right drawable (radio button), which ends up with radio text located in the middle between the two drawables.
I would like to have radio button text and left drawable(flag icon) has smaller space between, while radio button text and right drawable (radio button) has larger space between. How to define the different spaces for left drawable and right drawable of radio button ?
Simply check this:
<RadioButton
android:id="#+id/radio0"
style="#style/my_recording_title_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#null"
android:button="#null"
android:checked="true"
android:drawableRight="#drawable/presets_sel"
android:padding="12dp"
android:text="Play with EarPhones" />
<View
android:layout_width="fill_parent"
android:layout_height="3dp"
android:background="#drawable/line" />
<RadioButton
android:id="#+id/radio1"
style="#style/my_recording_title_text"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:background="#null"
android:button="#null"
android:drawableRight="#drawable/presets_sel"
android:padding="12dp"
android:text="Play with internal speakers" />
</RadioGroup>
try this xml file or add Property android:gravity="center_horizontal|center_vertical" or android:gravity="center" in your Radio Button and remove padding
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<RadioGroup
android:layout_width="fill_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="#+id/radioButton1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:drawableLeft="#drawable/logo"
android:button="#null"
android:drawableRight="#drawable/ic_launcher"
android:gravity="center_horizontal|center_vertical"
android:text="RadioButton" />
</RadioGroup>
</LinearLayout>
This sort of thing comes up often. And the sad truth is that the limitations of using RadioGroup with RadioButtons severely limit your ability to make your layouts look right.
I posted a very detailed solution here that involves abandoning RadioGroups. I know it seems like a lot of work, but the code is very straight-forward. Until RadioGroups are implemented in a better fashion, this is the best solution I've found.
Good luck!

How to change position of button in android?

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:gravity="center" android:background="#drawable/robo">
<TextView android:id="#+id/TextView02"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Max Time(Sec)">
</TextView>
<EditText android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="100"
android:id="#+id/maximum"
android:inputType="number">
</EditText>
<Button android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Start"
android:id="#+id/startbtn"
android:focusable="true">
</Button>
<ImageButton android:layout_height="wrap_content"
android:layout_width="wrap_content"
android:src="#drawable/icon"
android:id="#+id/imageButton1">
</ImageButton>
</LinearLayout>
In LinearLayout you can't change positions a whole lot - because the layout is Linear (sequential). But you can use layout_margin to somewhat move the widgets.
I don't know what you want to do, but you should look into FrameLayout (which will let you put the image anywhere!). My personal favorite is RelativeLayout.
Position depends on position of it's parent container/component (Layout) and on it's layout_* properties.
And u did'n tell what u want. If u want change it position - switch it with another view in Layout.
put more buttons in layout and hide or show them according to your needs
views in android are in relationship, not only in RelativeLayout but in Others, so you should choose the best way to describe your app layout, using more than one is commonly used.
to change position of label, you 'd better using AbsoluteLayout then using android:layout_x="", android:layout_y=""
what is your exact requirement???
you can put two buttons and make one visible and other one invisible or vice verse.or you can put layout_margin for all direction.And try to put all your component in different layout.

Categories

Resources