Thư viện tri thức trực tuyến
Kho tài liệu với 50,000+ tài liệu học thuật
© 2023 Siêu thị PDF - Kho tài liệu học thuật hàng đầu Việt Nam

Lập trình Android: Tạo Gallery pot
Nội dung xem thử
Mô tả chi tiết
Trung tâm Tin học – ĐH KHTN
GALLERY
Android có cung cấp cho ta 1 công cụ để xem ảnh (như 1 album). Công cụ này thật sự
tiện ích khi các bạn lập trình các ứng dụng quản lý SmartPhone. Cho nên trong phần
này mình sẽ tạo ra 1 demo nho nhỏ miêu tả cách tạo và hoạt động của Gallery như
sau:
Đầu tiên các bạn tạo 1 Project:
Project name: GalleryTest
Build Target: Android 2.3.3
Application name: GalleryTest
Package name: com.dac.GalleryTest
Create Activity: GalleryActivity
Kế tiếp các bạo add các hình tự chọn vào folder drawable-mdpi (thuộc folder res/). Các
bạn tự rename hình và điều chỉnh các tên hình trong code thì ứng dụng mới không phát
sinh lỗi được.
Sau đó các bạn đổi tên file main.xml thành gallery.xml và viết code như sau:
<?xml version="1.0" encoding="utf-8"?>
<Gallery xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/gallery"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
/>
Và trong file GalleryActivity.java:
package com.dac.GalleryTest
import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
Lập trình Android – http://laptrinhdidong.vn Page 1