Professional Documents
Culture Documents
Thiết bị di động
Chapter 5.3. Resources for Adaptive layout
Lưu ý
❖ Các slide trong bài giảng này dựa trên các bài
thực hành của Google Android Labs
❖ Original slides:
https://drive.google.com/drive/folders/1eu-
LXxiHocSktGYpG04PfE9Xmr_pBY5P
2
5.3 Adaptive layouts and
resources
3
Nội dung
4
Các layout thích nghi và
resources
6
Adaptive layout
● Layout thay đổi theo cấu hình
○ Kích thước màn hình
○ Hướng thiết bị
○ Theo địa phương/vùng miền
○ Theo phiên bản của Android
7
Resource folders of a small app
MyProject/
src/
Để tất cả tài nguyên dự
res/
drawable/ án của bạn trong thư
graphic.png mục res
layout/
activity_main.xml
list_iteminfo.xml
mipmap/
ic_launcher_icon.png
values/
strings.xml
8
Các thư mục phổ biến trong res
● drawable/, layout/, menu/
10
12
Đặt tên cho các alternative
resource folders
Tên thư mục của resource phải có định dạng sau
14
Adaptive layout đơn giản
GridLayout
● In values/integer.xml:
<integer name="grid_column_count">1</integer>
● In values/integer.xml-land:
<integer name="grid_column_count">2</integer>
Landscape Portrait
15
Smallest width
● Smallest-width (sw) trong tên thư mục định
nghĩa chiều rộng nhỏ nhất
○ res/values-swndp, where n is the smallest width
○ Example: res/values-sw600dp/dimens.xml
○ Does not change with orientation
18
Default
resources
19
20
Tìm hiểu thêm
● Supporting Multiple Screens
● Providing Resource
● Resources Overview
● Localization Guide
21
END
22