JavaScript is required

Which is correct for using any image with the name "trainstation"?

A.

Android:"@drawable/trainstation"

B.

Android:src="trainstation"

C.

Src=@drawable/trainstation

D.

Android:src="@drawable/trainstation"

Trả lời:

Đáp án đúng: D


Đáp án đúng là D. Android:src="@drawable/trainstation". Giải thích: Trong Android, để sử dụng một hình ảnh có tên "trainstation" từ thư mục drawable, bạn cần sử dụng cú pháp sau trong XML: `android:src="@drawable/trainstation"` Trong đó: * `android:src` là thuộc tính của View (ví dụ: ImageView) cho biết nguồn của hình ảnh. * `@drawable/trainstation` là một tham chiếu đến hình ảnh "trainstation" nằm trong thư mục drawable. Dấu `@` cho biết đây là một tài nguyên (resource). Các lựa chọn khác không đúng vì: * A. `Android:"@drawable/trainstation"`: Sai cú pháp, thiếu `src` và dấu ngoặc kép không đúng vị trí. * B. `Android:src="trainstation"`: Thiếu tiền tố `@drawable/`, Android sẽ không tìm thấy tài nguyên. * C. `Src=@drawable/trainstation`: Sai cú pháp, thuộc tính phải là `android:src` và cần dấu ngoặc kép.

Câu hỏi liên quan