Android Spinner Initial Padding -
i creating android app consists of form. form needs have edittext
, spinners
side-by-side (for chose linearlayout
). my final goal have text in spinner
align vertically text in edittext
; however, want have padding on options in expanded spinner
. padding messes spinner
alignment appears in form.
here code custom spinner
list item:
<textview android:id="@+id/transportation_spinner_item_textview" xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="match_parent" android:layout_height="wrap_content" android:padding="10dp" android:textcolor="@android:color/black" android:textsize="18dp"/>
here code main form:
<linearlayout android:id="@+id/linearlayout6" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_below="@+id/divider3" android:orientation="horizontal"> <relativelayout android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="100" android:orientation="vertical"> <textview android:id="@+id/ip_minutes_label" android:layout_width="wrap_content" android:layout_height="wrap_content" android:hint="@string/ip_minutes" android:layout_margintop="4dp" android:textsize="12sp"/> <spinner android:id="@+id/ip_minutes_spinner" android:layout_width="match_parent" android:layout_height="wrap_content" android:spinnermode="dialog" android:gravity="bottom"/> </relativelayout> <android.support.design.widget.textinputlayout android:id="@+id/ip_charge" android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="100" android:layout_gravity="bottom"> <edittext android:layout_width="match_parent" android:layout_height="wrap_content" android:layout_weight="100" android:editable="false" android:hint="@string/ip_charge"/> </android.support.design.widget.textinputlayout> </linearlayout>
and here image of how looks: image of alignment above code
i have been googling , trying adjust padding/margins of different views hours, if has suggestions, great. thanks!
i'm not sure understand, when say,
this padding messes spinner alignment appears in form.
do mean dropdownview? shows when spinner clicked?
if so, create separate layout dropdownview.
in arrayadapter have following methods,
public view getdropdownview(int position, view cnvtview, viewgroup prnt) public view getview(int pos, view cnvtview, viewgroup prnt)
just have them return 2 different views, e.g
@override public view getdropdownview(int position, view cnvtview, viewgroup prnt) { return getcustomdropdownview(position, cnvtview, prnt); } @override public view getview(int pos, view cnvtview, viewgroup prnt) { return getcustomview(pos, cnvtview, prnt); }
and
public view getcustomview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context.getsystemservice( context.layout_inflater_service ); view myspinner = inflater.inflate(r.layout.custom_spinner, parent, false); textview main_text = (textview) myspinner.findviewbyid(r.id.spinner_text); main_text.settext(spinnervalues[position]); return myspinner; } public view getcustomdropdownview(int position, view convertview, viewgroup parent) { layoutinflater inflater = (layoutinflater) context.getsystemservice( context.layout_inflater_service ); view myspinner = inflater.inflate(r.layout.custom_dropdown_spinner, parent, false); textview main_text = (textview) myspinner.findviewbyid(r.id.spinner_text); main_text.settext(spinnervalues[position]); return myspinner; }
Comments
Post a Comment