- Hands-On Android UI Development
- Jason Morris
- 626字
- 2021-07-02 23:26:08
Creating the category picker layout
Now, it's time to go back to the layout editor and start creating the category selector box with these icons:
- Reopen the content_capture_claim.xml layout file from the res/layout directory.
- In the Palette panel, open the AppCompat section and drag another CardView into the layout editor. Drop it below the CardView for the description, amount, and date input fields.
- In the Attributes panel, use the View all attributes toggle button and search box to find the layout margin.
- Open the Layout_Margins attribute group.
- Then, open the resource selector for the top attribute.
- Select the grid_spacer1 dimension resource you created earlier, and click on OK to close the resource selector:

- Then, in the Palette, open the Layouts section and drag a LinearLayout (vertical) into the new CardView.
- In the Attributes panel, use the resource selector to change the all margin attribute to grid_spacer1 to create some padding from the edges of the CardView.
- Clear the Attributes panel search box.
- Open the Containers section of the Palette, and drag a RadioGroup into the new LinearLayout in the layout editor. A RadioGroup is a specialized LinearLayout that handles the toggling of its child RadioButton widgets, which you'll use to allow the user to select a category.
- In the Attributes panel, change the id attribute to categories.
- In the Attributes panel, use the search box to find the orientation attribute and change it to horizontal.
- Clear the Attributes panel search box, and toggle it back to View fewer attributes.
- Open the Widgets section of the Palette and drag a RadioButton into the new RadioGroup.
- In the Attributes panel, change the ID to accommodation.
- Clear the layout_weight attribute.
- Use the resource editor for the button attribute to select the ic_category_accommodation you created earlier:

- Clear the text attribute, since these radio buttons won't have any labels.
- You'll then use the contentDescription attribute to store the human readable name of the category. Open the resource editor, create a new string resource named description_accommodation, and give it a value of Accommodation.
The contentDescription attribute is part of the accessibility system, and it's used by screen readers and similar aids to describe a component that might not have a text label. In this case, it's a perfect place for us to grab the human-readable description of a category. It's not an on-screen space, and it also serves users with accessibility enabled.
- Toggle the Attributes panel to view all the attributes, and then find the layout margins.
- Use the resource selector to change the end margin attribute to grid_spacer1.
- Repeat the process of adding and populating radio buttons for the categories, giving each of them a suitable name in their ID and contentDescription attributes. Leave the “other” category until last so that it appears to the right of all the others.
- In the Component Tree panel, select the RadioGroup.
- In the Attributes panel, change its layout_height to wrap_content.
- From the Palette, open the Text section and drag a TextView into place below the RadioGroup.
- In the Attributes panel, change the ID to selected_category.
- Clear the text attribute.
- Use the drop-down on the textAppearance attribute to select AppCompat.Medium.
- In the Component Tree, select the CardView containing the category selection components.
- Now in the Attributes panel, change the layout_height to wrap_content.
The CardView will wrap upward, packing in the radio buttons and the label that you will use to display the currently selected category name. The CardView, again, serves to visually group the categories, and helps the user understand how they use this area of the screen:

The use of standard styles and theming, again, helps the user to quickly grasp how things work; even though the categories are just a row of icons, they are underscored by the selected category name.
- Docker技術入門與實戰(第3版)
- MySQL 8 DBA基礎教程
- Scratch 3.0少兒編程與邏輯思維訓練
- Python Network Programming Cookbook(Second Edition)
- C++程序設計基礎教程
- JavaScript+Vue+React全程實例
- Linux操作系統基礎案例教程
- D3.js 4.x Data Visualization(Third Edition)
- Unity 2017 Mobile Game Development
- Regression Analysis with Python
- Django 5企業級Web應用開發實戰(視頻教學版)
- C++程序設計教程
- CodeIgniter Web Application Blueprints
- R語言數據挖掘:實用項目解析
- Docker:容器與容器云(第2版)