Nội Dung Chính
[ VIDEO TUT ]
Chú ý: Các bạn lựa chọn video ở chế độ 720HD để xem được chất lượng hình ảnh và âm thanh tốt nhất nhé.
Android Gravity
Dùng để thiết lập vị trí của giá trị thuộc tính android:text trên View.
Cách sử dụng
Bước 1: Mở file layout, thêm một view bất kỳ.
Bước 2: Truyền giá trị cho thuộc tính android:text của view vừa tạo.
Bước 3: Thiết lập giá trị cho thuộc tính android:gravity, với mỗi giá trị sẽ có 1 vị trí hiển thị tương ứng.
Học android cơ bản bằng video tại đây.
Trong ví dụ sau chúng ta sẽ tạo ra một Button trên layout, truyền giá trị cho thuộc tính android:text và cho nó hiển thị ở chính giữa Button.
1 2 3 4 5 6 7 8 9 10 11 12 13 | <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" android:layout_width="match_parent" android:layout_height="match_parent"> <Button android:layout_width="250dp" android:layout_height="200dp" android:text="Center" android:gravity="center" /> </LinearLayout> |
Các bài học android tiếp theo:
- Android cơ bản 14 – Android Text Customization (P.1)
- Android cơ bản 15 – Android Text Customization (P.2)
- Android cơ bản 16 – Android Linear Layout Using Java