- Hands-On Android UI Development
- Jason Morris
- 330字
- 2021-07-02 23:26:08
Adding the attachment preview
After completing the category selector box, roughly half the available layout space should be left empty underneath. This is where the user will be able to preview the attachments they have added to the claim. We want the user to be able to swipe through these attachments left and right, and the easiest way to allow this is a ViewPager. A ViewPager is a special type of Android widget that links to an Adapter (other examples are ListView, Spinner, and RecylerView). An Adapter object turns data (such as rows from a database cursor, or objects from a java.util.List) into widgets that can be displayed on the screen.
Follow these steps to add it to the layout:
- The ViewPager class is not available from the Palette panel, so at the bottom of the layout editor, change from Design mode to Text mode, so that you can edit the layout XML directly.
- Go to the bottom of the file and find the space between where the last CardView element is closed and where the LinearLayout is closed.
- Insert a ViewPager element into that space:
</android.support.v7.widget.CardView>
<android.support.v4.view.ViewPager
android:id="@+id/attachments"
android:clipChildren="false"
android:clipToPadding="false"
android:paddingBottom="@dimen/grid_spacer1"
android:layout_weight="1"
android:layout_width="wrap_content"
android:layout_height="0dp"
android:layout_marginTop="@dimen/grid_spacer1"/>
</LinearLayout>
- Change back to the Design view, and you'll note that a new box has been added to the layout and blueprints where the empty space was.
The clipChildren and clipToPadding attributes in the preceding code change how the ViewPager and its children treat the space around them when rendering. The CardView class draws its shadows outside of its boundaries, and by default, these are clipped by the graphics system. Turning the clipping off allows the shadows and borders to be rendered completely.
A ViewPager doesn't look like anything on its own; its children are the only things that make it appear visually. So, until the user has added an attachment to a claim, nothing will appear in this space. This is not a problem, since the empty area provides a space for the software keyboard to appear when they enter the description and amount.
- Design Principles for Process:driven Architectures Using Oracle BPM and SOA Suite 12c
- Java EE 6 企業(yè)級應(yīng)用開發(fā)教程
- Java系統(tǒng)分析與架構(gòu)設(shè)計
- JavaScript 從入門到項目實踐(超值版)
- Java面向?qū)ο笏枷肱c程序設(shè)計
- Python自動化運維快速入門
- Apache Hive Essentials
- MongoDB權(quán)威指南(第3版)
- Expert Data Visualization
- Learning Salesforce Einstein
- QGIS By Example
- PHP從入門到精通(第4版)(軟件開發(fā)視頻大講堂)
- Go語言從入門到精通
- Learning Kotlin by building Android Applications
- 零基礎(chǔ)學(xué)SQL(升級版)