BasicAccessibility / res / layout /

sample_main.xml

1
<!--
2
Copyright (C) 2013 The Android Open Source Project
3
 
4
Licensed under the Apache License, Version 2.0 (the "License");
5
you may not use this file except in compliance with the License.
6
You may obtain a copy of the License at
7
 
8
     http://www.apache.org/licenses/LICENSE-2.0
9
 
10
Unless required by applicable law or agreed to in writing, software
11
distributed under the License is distributed on an "AS IS" BASIS,
12
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
See the License for the specific language governing permissions and
14
limitations under the License.
15
-->
16
 
17
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
18
              xmlns:tools="http://schemas.android.com/tools"
19
              android:layout_width="match_parent"
20
              android:layout_height="match_parent"
21
              android:gravity="center_horizontal">
22
    <ScrollView
23
            android:layout_width="match_parent"
24
            android:layout_height="match_parent"
25
            android:fillViewport="false">
26
        <RelativeLayout
27
                android:layout_width="match_parent"
28
                android:layout_height="match_parent"
29
                android:paddingLeft="@dimen/activity_horizontal_margin"
30
                android:paddingRight="@dimen/activity_horizontal_margin"
31
                android:paddingTop="@dimen/activity_vertical_margin"
32
                android:paddingBottom="@dimen/activity_vertical_margin"
33
                tools:context=".MainActivity"
34
                >
35
 
36
            <!-- Notice the presence of nextFocusDown/nextFocusUp on the elements below. You can
37
            also use nextFocusLeft/nextFocusRight. This tells the system in what order elements
38
            should be navigated through. If not present, the system will make a guess based on
39
            element location in the layout. -->
40
            <TextView
41
                    android:layout_width="wrap_content"
42
                    android:layout_height="wrap_content"
43
                    android:text="Buttons"
44
                    android:id="@+id/buttonsLabel"
45
                    android:layout_alignParentTop="true"
46
                    android:layout_alignParentLeft="true"
47
                    android:nextFocusDown="@+id/composeButton"/>
48
 
49
            <!-- This is a regular, text-based button. No contentDescription is needed, since the
50
                 text field sufficiently describes the action performed. -->
51
            <Button
52
                    android:layout_width="wrap_content"
53
                    android:layout_height="wrap_content"
54
                    android:text="@string/composeButtonLabel"
55
                    android:id="@+id/composeButton"
56
                    android:layout_below="@+id/buttonsLabel"
57
                    android:layout_alignLeft="@+id/buttonsLabel"
58
                    android:nextFocusUp="@+id/buttonsLabel"
59
                    android:nextFocusDown="@+id/checkboxesLabel"
60
                    />
61
 
62
            <!-- The next two buttons are different types of image-based buttons. -->
63
 
65
            <!-- Adding a contentDescription is needed for accessibility, since no text is present.
66
            Since the contentDescription is read verbatim, you may want to be a bit more
67
            descriptive than usual, such as adding "button" to the end of your description, if
68
            appropriate. -->
69
            <ImageButton
70
                    android:layout_width="wrap_content"
71
                    android:layout_height="wrap_content"
72
                    android:id="@+id/discardButton"
73
                    android:layout_alignTop="@+id/composeButton"
74
                    android:layout_toRightOf="@+id/composeButton"
75
                    android:src="@drawable/ic_action_discard"
76
                    android:layout_alignBottom="@+id/composeButton"
77
                    android:contentDescription="@string/discardButtonDescription"
78
                    android:scaleType="fitCenter"
79
                    android:nextFocusUp="@+id/buttonsLabel"
80
                    android:nextFocusDown="@+id/checkboxesLabel"
81
                    />
83
 
84
            <ImageButton
85
                    android:layout_width="wrap_content"
86
                    android:layout_height="wrap_content"
87
                    android:id="@+id/infoButton"
88
                    android:layout_alignTop="@+id/discardButton"
89
                    android:layout_toRightOf="@+id/discardButton"
90
                    android:src="@drawable/ic_action_info"
91
                    android:layout_alignBottom="@+id/discardButton"
92
                    android:layout_alignRight="@+id/hyperspaceCheckbox"
93
                    android:scaleType="fitCenter"
94
                    android:background="?android:selectableItemBackground"
95
                    android:padding="5dp"
96
                    android:contentDescription="@string/infoButtonDescription"
97
                    android:nextFocusUp="@+id/buttonsLabel"
98
                    android:nextFocusDown="@+id/checkboxesLabel"
99
            />
100
 
101
            <TextView
102
                    android:layout_width="wrap_content"
103
                    android:layout_height="wrap_content"
104
                    android:text="@string/checkboxesLabel"
105
                    android:id="@+id/checkboxesLabel"
106
                    android:layout_below="@+id/composeButton"
107
                    android:layout_alignLeft="@+id/composeButton"
108
                    android:nextFocusUp="@+id/composeButton"
109
                    android:nextFocusDown="@+id/jetpackCheckbox"
110
                    />
111
 
112
            <!-- Like a text-based button, checkboxes with text will often work correctly as-is.
113
                 If your checkboxes do not have a text attribute, you will need to add a
114
                 contentDescriptoin. -->
115
            <CheckBox
116
                    android:layout_width="wrap_content"
117
                    android:layout_height="wrap_content"
118
                    android:text="@string/jetpackCheckboxLabel"
119
                    android:id="@+id/jetpackCheckbox"
120
                    android:layout_below="@+id/checkboxesLabel"
121
                    android:layout_alignLeft="@+id/checkboxesLabel"
122
                    android:checked="false"
123
                    android:nextFocusUp="@+id/checkboxesLabel"
124
                    android:nextFocusDown="@+id/hyperspaceCheckbox"
125
                    />
126
 
127
            <CheckBox
128
                    android:layout_width="wrap_content"
129
                    android:layout_height="wrap_content"
130
                    android:text="@string/hyperspaceCheckboxLabel"
131
                    android:id="@+id/hyperspaceCheckbox"
132
                    android:layout_below="@+id/jetpackCheckbox"
133
                    android:layout_alignLeft="@+id/jetpackCheckbox"
134
                    android:checked="false"
135
                    android:nextFocusUp="@+id/jetpackCheckbox"
136
                    android:nextFocusDown="@+id/imagesAndTextLabel"
137
                    />
138
 
139
            <TextView
140
                    android:layout_width="wrap_content"
141
                    android:layout_height="wrap_content"
142
                    android:text="@string/imagesAndTextLabel"
143
                    android:id="@+id/imagesAndTextLabel"
144
                    android:layout_below="@+id/hyperspaceCheckbox"
145
                    android:layout_alignLeft="@+id/hyperspaceCheckbox"
146
                    android:nextFocusUp="@+id/hyperspaceCheckbox"
147
                    android:nextFocusDown="@+id/partlyCloudImage"
148
                    />
149
 
150
            <!-- Images should have a contentDescription if they convey any meaningful
151
                 information. Images that are purely decorative may not need a contentDescription,
152
                 however. -->
153
            <ImageView
154
                    android:layout_width="wrap_content"
155
                    android:layout_height="wrap_content"
156
                    android:id="@+id/partlyCloudyImage"
157
                    android:layout_below="@+id/imagesAndTextLabel"
158
                    android:layout_alignLeft="@+id/imagesAndTextLabel"
159
                    android:src="@drawable/partly_cloudy"
160
                    android:contentDescription="@string/partlyCloudyDescription"
161
                    android:layout_alignRight="@+id/discardButton"
162
                    android:nextFocusUp="@+id/imagesAndTextLabel"
163
                    android:nextFocusDown="@+id/customViewLabel"
164
                    />
165
 
166
            <!-- TextViews are typically self describing, so do not need extra modifications. -->
167
            <TextView
168
                    android:layout_width="wrap_content"
169
                    android:layout_height="wrap_content"
170
                    android:textAppearance="?android:attr/textAppearanceLarge"
171
                    android:text="@string/temperature"
172
                    android:textSize="60sp"
173
                    android:id="@+id/temperatureText"
174
                    android:layout_alignTop="@+id/partlyCloudyImage"
175
                    android:layout_toRightOf="@+id/partlyCloudyImage"
176
                    android:layout_alignBottom="@+id/partlyCloudyImage"
177
                    android:gravity="center_vertical"
178
                    android:nextFocusUp="@+id/imagesAndTextLabel"
179
                    android:nextFocusDown="@+id/customViewLabel"
180
                    />
181
 
182
            <TextView
183
                    android:layout_width="wrap_content"
184
                    android:layout_height="wrap_content"
185
                    android:text="@string/customViewLabel"
186
                    android:id="@+id/customViewLabel"
187
                    android:layout_below="@+id/partlyCloudyImage"
188
                    android:layout_alignLeft="@+id/partlyCloudyImage"
189
                    android:nextFocusUp="@+id/partlyCloudImage"
190
                    android:nextFocusDown="@+id/dialView"
191
                    />
192
 
193
            <!-- Custom views require additonal code changes. See DialView.java for more
194
                 details. -->
195
            <com.example.android.basicaccessibility.DialView
196
                    android:layout_width="200dp"
197
                    android:layout_height="200dp"
198
                    android:id="@+id/dialView"
199
                    android:layout_below="@+id/customViewLabel"
200
                    android:layout_alignLeft="@+id/partlyCloudyImage"
201
                    android:nextFocusUp="@+id/customViewLabel"
202
                    />
203
 
204
        </RelativeLayout>
205
    </ScrollView>
206
</LinearLayout>