android - Custom layout for RadioButton -
is there way can change layout radiobutton , still have radiogroup recognise it?
what need layout include couple of edittext fields when user selected button fields become active. know can built custom part based on linearlayout , set own layout using: (linearlayout) layoutinflater.from(context).inflate(r.layout.my_layout, this, true) can't figure out how same thing radio button.
i have tried option of having fields outside radiogroup , lining them button doesn't work. seems device-dependant.
this original layout looked like:
<radiogroup android:id="@+id/time_selector_radio_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toleftof="@id/time_selector_hours_prompt" android:layout_below="@id/time_selector_hours_prompt" android:layout_alignparentright="true" android:gravity="right" android:orientation="vertical" android:checkedbutton="@+id/time_selector_first_radio" > <radiobutton android:id="@+id/time_selector_first_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="1dip" android:button="@drawable/radio_button_selector" /> <radiobutton android:id="@+id/time_selector_second_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="1dip" android:button="@drawable/radio_button_selector" /> <radiobutton android:id="@+id/time_selector_third_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="1dip" android:button="@drawable/radio_button_selector" /> <radiobutton android:id="@+id/time_selector_hours_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="1dip" android:button="@drawable/radio_button_selector" /> </radiogroup> <textview android:id="@+id/time_selector_all_day_prompt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toleftof="@id/time_selector_radio_group" android:layout_below="@id/time_selector_hours_prompt" android:layout_margintop="11dip" android:text="@string/time_all_day" /> <textview android:id="@+id/time_selector_before_noon_prompt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toleftof="@id/time_selector_radio_group" android:layout_below="@id/time_selector_all_day_prompt" android:layout_margintop="19dip" android:text="@string/time_before_noon" /> <textview android:id="@+id/time_selector_after_noon_prompt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toleftof="@id/time_selector_radio_group" android:layout_below="@id/time_selector_before_noon_prompt" android:layout_margintop="19dip" android:text="@string/time_after_noon" /> <textview android:id="@+id/time_selector_starting_time_prompt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@id/time_selector_starting_date_prompt" android:layout_below="@id/time_selector_after_noon_prompt" android:layout_margintop="20dip" android:layout_marginleft="2dip" android:text="@string/advanced_time_selector_dialog_starting_time_prompt" /> <edittext android:id="@+id/time_selector_starting_time" android:layout_width="@dimen/advanced_time_selector_edit_texts_width" android:layout_height="wrap_content" android:layout_alignright="@id/time_selector_starting_date" android:layout_alignbaseline="@id/time_selector_starting_time_prompt" android:textsize="14sp" android:paddingright="10dip" android:paddingleft="10dip" android:gravity="center" android:singleline="true" android:maxwidth="@dimen/advanced_time_selector_edit_texts_width" android:background="@drawable/text_field_bg" android:inputtype="datetime" /> <textview android:id="@+id/time_selector_ending_time_prompt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_alignright="@id/time_selector_ending_date_prompt" android:layout_alignbottom="@id/time_selector_starting_time_prompt" android:layout_alignbaseline="@id/time_selector_starting_time_prompt" android:layout_marginright="2dip" android:layout_marginleft="2dip" android:text="@string/ending_date_prompt" /> <edittext android:id="@+id/time_selector_ending_time" android:layout_width="@dimen/advanced_time_selector_edit_texts_width" android:layout_height="wrap_content" android:layout_alignright="@id/time_selector_ending_date" android:layout_alignbaseline="@id/time_selector_ending_time_prompt" android:textsize="14sp" android:paddingright="10dip" android:paddingleft="10dip" android:gravity="center" android:singleline="true" android:maxwidth="@dimen/advanced_time_selector_edit_texts_width" android:background="@drawable/text_field_bg" android:inputtype="datetime" />
note button doesn't have text , added in textview can have on left. happening text "creeping up".
so, changed this:
<radiogroup android:id="@+id/time_selector_radio_group" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_toleftof="@id/time_selector_hours_prompt" android:layout_below="@id/time_selector_hours_prompt" android:layout_alignparentright="true" android:layout_marginright="30dip" android:gravity="right" android:orientation="vertical" android:checkedbutton="@+id/time_selector_first_radio" > <radiobutton android:id="@+id/time_selector_all_day_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="1dip" android:button="@null" android:drawableright="@drawable/radio_button_selector" android:text="@string/time_all_day" android:textcolor="@color/content_text_color" /> <radiobutton android:id="@+id/time_selector_before_noon_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="1dip" android:button="@null" android:drawableright="@drawable/radio_button_selector" android:text="@string/time_before_noon" android:textcolor="@color/content_text_color" /> <radiobutton android:id="@+id/time_selector_after_noon_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="1dip" android:button="@null" android:drawableright="@drawable/radio_button_selector" android:text="@string/time_after_noon" android:textcolor="@color/content_text_color" /> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal"> <radiobutton android:id="@+id/time_selector_hours_radio" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_margintop="1dip" android:button="@null" android:drawableright="@drawable/radio_button_selector" android:layout_alignparentright="true" android:text="@string/advanced_time_selector_dialog_starting_time_prompt" android:textcolor="@color/content_text_color" android:layout_marginleft="-1dip" android:paddingleft="-1dip" /> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_toleftof="@id/time_selector_hours_radio" android:layout_alignparentleft="true"> <edittext android:id="@+id/time_selector_starting_time" android:layout_width="@dimen/advanced_time_selector_edit_texts_width" android:layout_height="wrap_content" android:textsize="14sp" android:paddingright="10dip" android:paddingleft="10dip" android:gravity="center" android:singleline="true" android:maxwidth="@dimen/advanced_time_selector_edit_texts_width" android:background="@drawable/text_field_bg" android:layout_alignparentright="true" android:layout_alignbaseline="@id/time_selector_hours_radio" android:inputtype="datetime" /> <textview android:id="@+id/time_selector_ending_time_prompt" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginright="2dip" android:layout_marginleft="2dip" android:text="@string/ending_date_prompt" android:layout_alignbaseline="@id/time_selector_hours_radio" android:layout_toleftof="@id/time_selector_starting_time" /> <edittext android:id="@+id/time_selector_ending_time" android:layout_width="@dimen/advanced_time_selector_edit_texts_width" android:layout_height="wrap_content" android:textsize="14sp" android:paddingright="10dip" android:paddingleft="10dip" android:gravity="center" android:singleline="true" android:maxwidth="@dimen/advanced_time_selector_edit_texts_width" android:layout_toleftof="@id/time_selector_ending_time_prompt" android:layout_alignbaseline="@id/time_selector_hours_radio" android:background="@drawable/text_field_bg" android:inputtype="datetime" /> </relativelayout> </relativelayout> </radiogroup>
it still not perfect and, of course, doesn't recognise radiogroup.
i wanted go direction of extending radiobutton have no idea how change layout there.
i wrote custom radiogroup
called radiogroupplus
traverse through it's children , find radiobutton
regardless how deep radiobutton
nested, link radiobutton
found together.
you can find repo here: https://github.com/worker8/radiogroupplus
the readme
of repo covers how use it, , works how imagine it, example:
<worker8.com.github.radiogroupplus.radiogroupplus android:id="@+id/radio_group_plus" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical"> <linearlayout...> <imageview...> <textview...> <radiobutton...> </linearlayout> <linearlayout...> <imageview...> <textview...> <radiobutton...> </linearlayout> <linearlayout...> <imageview...> <textview...> <radiobutton...> </linearlayout> </worker8.com.github.radiogroupplus.radiogroupplus>
will give this:
in case, since have xml layout file, try download radiogroupplus
following guide here:
add top level build.gradle:
allprojects { repositories { maven { url "https://jitpack.io" } } }
add under dependencies:
compile 'com.github.worker8:radiogroupplus:v1.0.1'
then in xml, change radiogroup
worker8.com.github.radiogroupplus.radiogroupplus
. radiobutton
s under radiogroupplus
should linked together.
hope helps!
Comments
Post a Comment