Sử dụng bộ sưu tập để sắp xếp ngăn nắp các trang
Lưu và phân loại nội dung dựa trên lựa chọn ưu tiên của bạn.
Việc phát triển trang web và ứng dụng cho thiết bị di động đặt ra những thách thức khác nhau so với
đến việc phát triển một trang web dành cho trình duyệt web dành cho máy tính. Các phương pháp sau có thể giúp bạn cung cấp
ứng dụng web hiệu quả nhất dành cho Android và các thiết bị di động khác.
Chuyển hướng thiết bị di động sang phiên bản chuyên dụng dành cho thiết bị di động của trang web. Có một vài
để thực hiện việc này
bằng cách sử dụng chuyển hướng phía máy chủ. Một phương pháp phổ biến là "ngửi" thời gian
Chuỗi Tác nhân người dùng do trình duyệt web cung cấp. Để xác định
có phân phát phiên bản trên thiết bị di động của trang web hay không, hãy tìm phiên bản "thiết bị di động" trong Tác nhân người dùng.
Sử dụng HTML5
cho thiết bị di động. HTML5 là ngôn ngữ đánh dấu phổ biến nhất được sử dụng cho các trang web dành cho thiết bị di động.
Tiêu chuẩn này khuyến khích phát triển ưu tiên thiết bị di động để đảm bảo rằng trang web hoạt động trên nhiều
thiết bị. Không giống như các ngôn ngữ web trước đây, HTML5 sử dụng <DOCTYPE> và
charset khai báo:
<!DOCTYPEhtml>
...
<metacharset="UTF-8">
Sử dụng siêu dữ liệu khung nhìn để đổi kích thước trang web của bạn cho phù hợp. Trong tài liệu của bạn
<head>, hãy cung cấp siêu dữ liệu chỉ rõ cách bạn muốn khung nhìn của trình duyệt
hiển thị trang web của bạn. Ví dụ: siêu dữ liệu khung nhìn có thể chỉ định chiều cao và chiều rộng cho
khung nhìn của trình duyệt, tỷ lệ trang ban đầu và mật độ màn hình mục tiêu.
Ví dụ sau đây trình bày cách thiết lập siêu dữ liệu của khung nhìn:
Sử dụng bố cục tuyến tính dọc. Tránh việc người dùng phải cuộn sang trái và phải khi
điều hướng trang của bạn. Người dùng có thể cuộn lên và xuống dễ dàng hơn và làm cho trang của bạn đơn giản hơn.
Đặt chiều cao và chiều rộng của bố cục thành match_parent. Cài đặt
WebView chiều cao và chiều rộng của đối tượng thành
match_parent đảm bảo các thành phần hiển thị của ứng dụng có kích thước chính xác. Chúng tôi không khuyến khích việc đặt
thành wrap_content vì điều này dẫn đến việc định cỡ không chính xác. Tương tự, việc đặt
chiều rộng bố cục thành wrap_content không được hỗ trợ và khiến WebView của bạn
hãy sử dụng chiều rộng của thành phần mẹ. Do đó, bạn cần đảm bảo rằng không có
chiều cao và chiều rộng của đối tượng bố cục mẹ của đối tượng WebView được đặt thành
wrap_content
Tránh yêu cầu nhiều tệp. Vì thiết bị di động thường có tốc độ kết nối
chậm hơn máy tính để bàn, hãy làm cho trang của bạn tải nhanh nhất có thể. Một cách để tăng tốc độ đó là
tránh tải các tệp bổ sung như biểu định kiểu và tệp tập lệnh trong <head>.
Ngoài ra, hãy cân nhắc
thực hiện phân tích trên thiết bị di động với
PageSpeed Insights của Google cung cấp các đề xuất tối ưu hóa chi tiết dành riêng cho ứng dụng của bạn.
Nội dung và mã mẫu trên trang này phải tuân thủ các giấy phép như mô tả trong phần Giấy phép nội dung. Java và OpenJDK là nhãn hiệu hoặc nhãn hiệu đã đăng ký của Oracle và/hoặc đơn vị liên kết của Oracle.
Cập nhật lần gần đây nhất: 2025-07-27 UTC.
[[["Dễ hiểu","easyToUnderstand","thumb-up"],["Giúp tôi giải quyết được vấn đề","solvedMyProblem","thumb-up"],["Khác","otherUp","thumb-up"]],[["Thiếu thông tin tôi cần","missingTheInformationINeed","thumb-down"],["Quá phức tạp/quá nhiều bước","tooComplicatedTooManySteps","thumb-down"],["Đã lỗi thời","outOfDate","thumb-down"],["Vấn đề về bản dịch","translationIssue","thumb-down"],["Vấn đề về mẫu/mã","samplesCodeIssue","thumb-down"],["Khác","otherDown","thumb-down"]],["Cập nhật lần gần đây nhất: 2025-07-27 UTC."],[],[],null,["# Best practices for web apps\n\nDeveloping web pages and applications for mobile devices presents different challenges compared\nto developing a web page for desktop web browsers. The following practices can help you provide the\nmost effective web application for Android and other mobile devices.\n\n1. **Redirect mobile devices to a dedicated mobile version of your website.** There are several ways to do this using server-side redirects. One common method is to \"sniff\" the User Agent string provided by the web browser. To determine whether to serve a mobile version of your site, look for the \"mobile\" string in the User Agent.\n| **Note:** Large-screen Android-powered devices that are served full-size websites---such as tablets---don't include the \"mobile\" string in the User Agent, while the rest of the User Agent string is mostly the same. As such, it's important you deliver the mobile version of your website based on whether the \"mobile\" string exists in the User Agent.\n2. **Use [HTML5](https://developer.mozilla.org/en-US/docs/Web/Guide/HTML/HTML5)\n for mobile devices.** HTML5 is the most common markup language used for mobile websites. This standard encourages mobile-first development to help ensure that websites work on a variety of devices. Unlike previous web languages, HTML5 uses simpler `\u003cDOCTYPE\u003e` and `charset` declarations: \n\n ```xml\n \u003c!DOCTYPE html\u003e\n ...\n \u003cmeta charset=\"UTF-8\"\u003e\n ```\n3. **Use viewport metadata to properly resize your web page.** In your document `\u003chead\u003e`, provide metadata that specifies how you want the browser's viewport to render your web page. For example, your viewport metadata can specify the height and width for the browser's viewport, the initial page scale, and the target screen density.\n\n The following example shows how to set viewport metadata: \n\n ```xml\n \u003cmeta name=\"viewport\" content=\"width=device-width, initial-scale=1.0, user-scalable=no\"\u003e\n ```\n\n For more information about how to use viewport metadata for Android-powered devices, read [Support different screens in web apps](/guide/webapps/targeting).\n4. **Use a vertical linear layout.** Avoid the need for the user to scroll left and right while navigating your page. Scrolling up and down is easier for the user and makes your page simpler.\n5. **Set the layout height and width to `match_parent`.** Setting your [`WebView`](/reference/android/webkit/WebView) object's height and width to `match_parent` makes sure your app's views are sized correctly. We discourage setting the height to `wrap_content` because it results in incorrect sizing. Similarly, setting the layout width to `wrap_content` isn't supported and causes your `WebView` to use the width of its parent instead. Because of this behavior, it's also important to make sure none of your `WebView` object's parent layout objects have their height and width set to `wrap_content`.\n6. **Avoid multiple file requests.** Because mobile devices typically have a connection speed slower than desktop computers, make your page load as fast as possible. One way to speed it up is to avoid loading extra files such as stylesheets and script files in the `\u003chead\u003e`. Also, consider [performing mobile analysis with\n Google's PageSpeed Insights](https://developers.google.com/speed/docs/insights/v5/get-started) for detailed optimization suggestions specific to your app.\n\nAdditional resources\n--------------------\n\n- [Pixel-Perfect UI in the WebView](https://developers.google.com/chrome/mobile/docs/webview/pixelperfect)\n- [Learn Responsive Design](http://www.html5rocks.com/en/mobile/responsivedesign/)\n- [High DPI images for variable pixel densities](http://www.html5rocks.com/en/mobile/high-dpi/)\n- [Mobile Web Best Practices](http://www.w3.org/TR/mobile-bp/)\n- [Make the Web Faster](https://developers.google.com/speed/overview)"]]