By default, Android Studio will preview the Spinner with their sample title and label data. To make designing more productive, it is better if I can change Spinner to preview with my own data.
Luckily, It is possible to do this in Android Studio. Here is how
1 Create layout xml file contain preview data.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <? xml version = "1.0" encoding = "utf-8" ?> android:layout_width = "match_parent" android:layout_height = "match_parent" android:paddingBottom = "@dimen/activity_vertical_margin" android:paddingLeft = "@dimen/activity_horizontal_margin" android:paddingRight = "@dimen/activity_horizontal_margin" android:paddingTop = "@dimen/activity_vertical_margin" tools:context = "com.example.piyapan039285.helloworld.AboutActivity" > < TextView android:layout_width = "wrap_content" android:layout_height = "wrap_content" android:text = "8:00" android:id = "@+id/tvAbout" /> </ RelativeLayout > |
2 In Spinner, add attribute
tools:listItem
like this1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | <? xml version = "1.0" encoding = "utf-8" ?> < RelativeLayout android:layout_width = "match_parent" android:layout_height = "match_parent" android:paddingBottom = "@dimen/activity_vertical_margin" android:paddingLeft = "@dimen/activity_horizontal_margin" android:paddingRight = "@dimen/activity_horizontal_margin" android:paddingTop = "@dimen/activity_vertical_margin" tools:context = "com.example.piyapan039285.helloworld.TableLayoutMainActivity" > < Spinner android:id = "@+id/spTimes" android:layout_width = "96dp" android:layout_height = "wrap_content" android:layout_alignParentRight = "true" tools:listitem = "@layout/your_preview_xml_file_name" /> </ RelativeLayout > |
3 If everything is OK, Android Studio will preview spinner to you like this
Happy Coding!
No comments:
Post a Comment