- 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.
- DB2 V9權威指南
- JavaScript從入門到精通(微視頻精編版)
- ReSharper Essentials
- Rust編程:入門、實戰與進階
- 零基礎玩轉區塊鏈
- 神經網絡編程實戰:Java語言實現(原書第2版)
- 網絡爬蟲原理與實踐:基于C#語言
- 琢石成器:Windows環境下32位匯編語言程序設計
- Jupyter數據科學實戰
- Express Web Application Development
- Java編程的邏輯
- 區塊鏈底層設計Java實戰
- 新一代SDN:VMware NSX 網絡原理與實踐
- Python:Deeper Insights into Machine Learning
- Laravel Application Development Blueprints