Lập trình Android: Tạo bảng màu với ScrollView pptx

3 886 1
Lập trình Android: Tạo bảng màu với ScrollView pptx

Đang tải... (xem toàn văn)

Thông tin tài liệu

Trung tâm Tin học – ĐH KHTN Tạo bảng màu với ScrollView Sau đây mình sẽ demo các sữ dụng ScrollView để tạo bảng màu (Các bạn có thể tạo những cái khác như trang tin tức, menu…). Trong ScrollView các bạn có thể lập trình thành nhiều lớp thực hiện các công việc khác nhau. 1/ Các bạn tạo 1 Project như sau: Project name: BangMau Build Target: Android 2.3.3 Application name: BangMau Package name: com.dac.BangMau Create Activity: BangMauActivity 2/ Tiếp theo các bạn tao giao diện như sau: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="fill_parent" android:layout_height="fill_parent" > <TextView android:layout_width="fill_parent" android:layout_height="wrap_content" android:text="@string/hello" /> <ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="0"> <TableRow> <View android:layout_height="80px" android:background="#000000"/> <TextView android:text="#000000" android:paddingLeft="4px" android:layout_gravity="center_vertical" /> </TableRow> <TableRow> <View android:layout_height="80px" android:background="#440000" /> Lập trình Android – http://laptrinhdidong.vn Page 1 Trung tâm Tin học – ĐH KHTN <TextView android:text="#440000" android:paddingLeft="4px" android:layout_gravity="center_vertical" /> </TableRow> <TableRow> <View android:layout_height="80px" android:background="#884400" /> <TextView android:text="#884400" android:paddingLeft="4px" android:layout_gravity="center_vertical" /> </TableRow> <TableRow> <View android:layout_height="80px" android:background="#aa8844" /> <TextView android:text="#aa8844" android:paddingLeft="4px" android:layout_gravity="center_vertical" /> </TableRow> <TableRow> <View android:layout_height="80px" android:background="#ffaa88" /> <TextView android:text="#ffaa88" android:paddingLeft="4px" android:layout_gravity="center_vertical" /> </TableRow> <TableRow> <View android:layout_height="80px" android:background="#ffffaa" /> <TextView android:text="#ffffaa" android:paddingLeft="4px" android:layout_gravity="center_vertical" /> </TableRow> <TableRow> <View android:layout_height="80px" android:background="#ffffff" /> <TextView android:text="#ffffff" android:paddingLeft="4px" android:layout_gravity="center_vertical" /> </TableRow> </TableLayout> </ScrollView> </LinearLayout> Vậy trong LinearLayout thì ta tạo 1 ScrollView . Trong ScrollView ta sẽ chia ra thành các TableRow khác nhau. Mỗi TableRow sẽ chứa 1 View để hiển thị màu và 1 Text Lập trình Android – http://laptrinhdidong.vn Page 2 Trung tâm Tin học – ĐH KHTN hiển thị ký hiệu màu đó (có thể chỉnh lại bằng tên màu bằng cách thay đổi thuộc tính Text). Kết quả sau khi debug như sau: Mọi ý kiến đóng góp các bạn vui lòng post bài vào forum trang web www.laptrinhdidong.vn . Rất mong nhận đc phản hồi của các bạn. Mình sẽ cập nhật trang web thường xuyên ^^ Lập trình Android – http://laptrinhdidong.vn Page 3 . KHTN Tạo bảng màu với ScrollView Sau đây mình sẽ demo các sữ dụng ScrollView để tạo bảng màu (Các bạn có thể tạo những cái khác như trang tin tức, menu…). Trong ScrollView các bạn có thể lập trình. < ;ScrollView xmlns:android="http://schemas.android.com/apk/res/android" android:layout_width="fill_parent" android:layout_height="wrap_content"> <TableLayout android:layout_width="fill_parent" android:layout_height="fill_parent" android:stretchColumns="0"> <TableRow> <View android:layout_height="80px" android:background="#000000"/> <TextView android:text="#000000" android:paddingLeft="4px" android:layout_gravity="center_vertical". /> </TableRow> <TableRow> <View android:layout_height="80px" android:background="#440000" /> Lập trình Android – http://laptrinhdidong.vn Page 1 Trung tâm Tin học – ĐH KHTN <TextView android:text="#440000" android:paddingLeft="4px" android:layout_gravity="center_vertical"

Ngày đăng: 07/08/2014, 23:20

Tài liệu cùng người dùng

Tài liệu liên quan