Recently need to use Datepicke and timepicker together, but found a problem, through the XML layout file cannot jump size style, XML file content is as follows
<?xml version= "1.0" encoding= "Utf-8"? ><linearlayout xmlns:android= "http://schemas.android.com/apk/res/ Android " android:layout_width=" match_parent " android:layout_height=" match_parent " android:o rientation= "Horizontal" > <datepicker android:id= "@+id/date_picker" android:layout_width= " Wrap_content " android:layout_height=" wrap_content " android:layout_gravity=" center_vertical " Android:calendarviewshown= "false"/> <timepicker android:id= "@+id/time_picker" android: Layout_width= "Wrap_content" android:layout_height= "wrap_content" android:layout_gravity= "Center_ Vertical "/></linearlayout>
Screen Big mobile phone can display full, but the small is so, finally through the access to data to solve the problem, the solution is as follows:
/** * Adjust framelayout size * @param tp */private void Resizepikcer (framelayout tp) {list<numberpicker> nplist = FindNumber Picker (TP); for (Numberpicker np:nplist) {Resizenumberpicker (NP);}} /** * Get viewgroup inside the Numberpicker component * @param viewgroup * @return */private list<numberpicker> findnumberpicker ( ViewGroup viewgroup) {list<numberpicker> nplist = new arraylist<numberpicker> (); View child = Null;if (null! = ViewGroup) {for (int i = 0; i < Viewgroup.getchildcount (); i++) {child = Viewgroup.getchildat (i); if (child instanceof Numberpicker) {Nplist.add ((numberpicker) child);} else if (child instanceof linearlayout) {list<numberpicker> result = Findnumberpicker ((viewgroup) child); Result.size () >0) {return result;}}} return nplist;} /* * Adjust Numberpicker size */private void Resizenumberpicker (Numberpicker np) {Linearlayout.layoutparams params = new Linearlayout.layoutparams (layoutparams.wrap_content);p arams.setmargins (0, 0); Np.setlayoutparams (params ); }
Then the call is done:
Final DatePicker DatePicker = (DatePicker) View.findviewbyid (r.id.date_picker); Final Timepicker Timepicker = (timepicker) View.findviewbyid (r.id.time_picker); Resizepikcer (DatePicker);//adjust DatePicker size resizepikcer (timepicker);//Adjust Timepicker size
Look at the adjustment:
Is it very simple, the text can also be changed, through style, examples are as follows:
http://download.csdn.net/detail/msn465780/8447723
Click to open link
Android solves DatePicker and Timepicker with layout style issues caused by