TAILIEUCHUNG - Lập trình Androi part 04

Trong khi đó là kỹ thuật có thể tạo ra và đính kèm các vật dụng để hoạt động của bạn hoàn toàn thông qua code Java, như chúng tôi đã làm trong chương trước, phương pháp phổ biến hơn là sử dụng một tập tin bố trí dựa trên XML. Dynamic instantiation vật dụng được dành riêng cho nhiều tình huống phức tạp, nơi mà các vật dụng vẫn chưa được biết thời gian biên dịch (ví dụ, populating một cột của các nút radio dựa trên dữ liệu lấy từ Internet) | Chapter Using XML-Based Layouts While it is technically possible to create and attach widgets to your activity purely through Java code as we did in the preceding chapter the more common approach is to use an XML-based layout file. Dynamic instantiation of widgets is reserved for more complicated scenarios where the widgets are not known at compile time . populating a column of radio buttons based on data retrieved from the Internet . With that in mind it s time to break out the XML and learn how to lay out Android activities that way. What Is an XML-Based Layout As the name suggests an XML-based layout is a specification of widgets relationships to each other and to their containers which are covered in Chapter 6 encoded in XML format. Specifically Android considers XML-based layouts to be resources and as such layout files are stored in the res layout directory inside your Android project. Each XML file contains a tree of elements specifying a layout of widgets and containers that make up one View hierarchy. The attributes of the XML elements are properties describing how a widget should look or how a container should behave. For example if a Button element has an attribute value of android textStyle bold that means that the text appearing on the face of the button should be rendered in a boldface font style. Android s SDK ships with a tool aapt that uses the layouts. This tool should be automatically invoked by your Android toolchain . Eclipse or Ant s . Of particular importance to you as a developer is that aapt generates the source file within your project allowing you to access layouts and widgets within those layouts directly from your Java code as will be demonstrated in this chapter. 23 CHAPTER 4 Using XML-Based Layouts Why Use XML-Based Layouts Most everything you do using XML layout files can be achieved through Java code. For example you could use setTypeface to have a button render its text in bold instead of using a property in

TAILIEUCHUNG - Chia sẻ tài liệu không giới hạn
Địa chỉ : 444 Hoang Hoa Tham, Hanoi, Viet Nam
Website : tailieuchung.com
Email : tailieuchung20@gmail.com
Tailieuchung.com là thư viện tài liệu trực tuyến, nơi chia sẽ trao đổi hàng triệu tài liệu như luận văn đồ án, sách, giáo trình, đề thi.
Chúng tôi không chịu trách nhiệm liên quan đến các vấn đề bản quyền nội dung tài liệu được thành viên tự nguyện đăng tải lên, nếu phát hiện thấy tài liệu xấu hoặc tài liệu có bản quyền xin hãy email cho chúng tôi.
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.