Android buttons resized out of parent on Text change -
i'm creating basic form activity user selects 1 button each row of buttons , submits backend database.
each button togglebutton
custom code make behave radio button (i.e. 1 per radiogroup
can selected @ time). each horizontal row of buttons belongs distinct radiogroup
.
this , good, when loading onto phone different aspect ratio, there's odd layout behavior:
the text in button doesn't fit, wraps around. that's expected, @ same time, button randomly drops down arbitrary number of pixels , lower edge sliced off container, refuses wrap_content
around button. button still functions normal, light @ bottom doesn't display, there's no way know it's selected when bug occurs.
what missing?
layout.xml:
<?xml version="1.0" encoding="utf-8"?> <scrollview android:id="@+id/mainscrollview" android:layout_width="match_parent" android:layout_height="match_parent" xmlns:android="http://schemas.android.com/apk/res/android"> <linearlayout android:id="@+id/mainlinearlayout" android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="vertical" android:paddingbottom="@dimen/activity_vertical_margin" android:paddingleft="@dimen/activity_horizontal_margin" android:paddingright="@dimen/activity_horizontal_margin" android:paddingtop="@dimen/activity_vertical_margin"> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content"> <textview android:id="@+id/timertextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_marginleft="10dp" android:layout_marginstart="10dp" android:text="@string/activity_record_default_clock_display_time" android:paddingright="10dp" /> <textview android:id="@+id/recordcountheadertextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@+id/timertextview" android:text="records: " /> <textview android:id="@+id/recordcounttextview" android:layout_width="wrap_content" android:layout_height="wrap_content" android:layout_torightof="@+id/recordcountheadertextview" android:text="0" /> </relativelayout> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/activity_record_vehicle_type" android:id="@+id/textview" android:textappearance="@android:style/textappearance.devicedefault.large" android:layout_gravity="center_horizontal" /> <radiogroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/vehiclegroup"> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_car" android:textoff="@string/activity_record_car" android:texton="@string/activity_record_car" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_truck" android:textoff="@string/activity_record_truck" android:texton="@string/activity_record_truck" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_suv" android:textoff="@string/activity_record_suv" android:texton="@string/activity_record_suv" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_van" android:textoff="@string/activity_record_van" android:texton="@string/activity_record_van" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_motorcycle" android:textoff="@string/activity_record_cycle" android:texton="@string/activity_record_cycle" android:onclick="ontoggle" android:layout_weight="1" android:checked="false" /> </radiogroup> <textview android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/activity_record_driver" android:id="@+id/textview2" android:layout_margintop="18dp" android:textappearance="@android:style/textappearance.devicedefault.large" android:layout_gravity="center_horizontal" /> <radiogroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/drivergendergroup"> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_driver_m" android:textoff="@string/activity_record_male" android:texton="@string/activity_record_male" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_driver_f" android:textoff="@string/activity_record_female" android:texton="@string/activity_record_female" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_driver_u" android:textoff="@string/activity_record_unknown" android:texton="@string/activity_record_unknown" android:onclick="ontoggle" android:layout_weight="1" /> </radiogroup> <radiogroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/driverprotectedgroup"> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_driver_protected" android:textoff="@string/activity_record_protected" android:texton="@string/activity_record_protected" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_driver_notprotected" android:textoff="@string/activity_record_not" android:texton="@string/activity_record_not" android:onclick="ontoggle" android:layout_weight="1" android:checked="false" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_driver_unknownprotected" android:textoff="@string/activity_record_unknown" android:texton="@string/activity_record_unknown" android:onclick="ontoggle" android:layout_weight="1" /> </radiogroup> <checkedtextview android:checkmark="?android:attr/listchoiceindicatormultiple" android:checked="false" android:layout_margintop="18dp" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="@string/activity_record_passenger" android:id="@+id/textview3" android:textappearance="@android:style/textappearance.devicedefault.large" android:layout_gravity="center_horizontal" /> <radiogroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/passengergendergroup"> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_passenger_m" android:textoff="@string/activity_record_male" android:texton="@string/activity_record_male" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_passenger_f" android:textoff="@string/activity_record_female" android:texton="@string/activity_record_female" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_passenger_u" android:textoff="@string/activity_record_unknown" android:texton="@string/activity_record_unknown" android:onclick="ontoggle" android:layout_weight="1" /> </radiogroup> <radiogroup android:layout_width="match_parent" android:layout_height="wrap_content" android:orientation="horizontal" android:id="@+id/passengerprotectedgroup"> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_passenger_protected" android:textoff="@string/activity_record_protected" android:texton="@string/activity_record_protected" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_passenger_notprotected" android:textoff="@string/activity_record_not" android:texton="@string/activity_record_not" android:onclick="ontoggle" android:layout_weight="1" /> <togglebutton android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:id="@+id/btn_passenger_unknownprotected" android:textoff="@string/activity_record_unknown" android:texton="@string/activity_record_unknown" android:onclick="ontoggle" android:layout_weight="1" /> </radiogroup> <relativelayout android:layout_width="wrap_content" android:layout_height="wrap_content"> <button android:id="@+id/btn_end_site" android:layout_width="wrap_content" android:layout_height="wrap_content" android:minheight="60dp" android:layout_alignparentleft="true" android:layout_alignparentstart="true" android:text="@string/activity_record_end_site" android:onclick="quit"/> <button android:layout_width="fill_parent" android:layout_height="wrap_content" android:minheight="60dp" android:layout_torightof="@id/btn_end_site" android:layout_toendof="@id/btn_end_site" android:id="@+id/btn_send" android:text="@string/activity_record_record" android:onclick="send" /> </relativelayout> </linearlayout> </scrollview>
you can use 2 methods solve problem..
solution 1
use android:layout_height="match_parent"
togglebutton
every button increase size based on large text button.
also have set:
android:layout_height="0dp" android:layout_weight="1"
for root layout make flexible.
<radiogroup android:id="@+id/vehiclegroup" android:layout_width="match_parent" android:layout_height="0dp" android:layout_weight="1" android:orientation="horizontal"> <togglebutton android:id="@+id/btn_car" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:minheight="60dp" android:onclick="ontoggle" android:textoff="textddddddds" android:texton="text" /> <togglebutton android:id="@+id/btn_truck" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:minheight="60dp" android:onclick="ontoggle" android:textoff="text" android:texton="text" /> <togglebutton android:id="@+id/btn_suv" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:minheight="60dp" android:onclick="ontoggle" android:textoff="text" android:texton="text" /> <togglebutton android:id="@+id/btn_van" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:minheight="60dp" android:onclick="ontoggle" android:textoff="text" android:texton="text" /> <togglebutton android:id="@+id/btn_motorcycle" android:layout_width="fill_parent" android:layout_height="match_parent" android:layout_weight="1" android:checked="false" android:minheight="60dp" android:onclick="ontoggle" android:textoff="textdd" android:texton="text" /> </radiogroup>
output:
solution 2
use android:singleline="true"
togglebutton
text not go next line , views exact shape
Comments
Post a Comment