Header ads

Header ads
» » Frame Layout

FrameLayout trong Android

FrameLayout là một ViewGroup được sử dụng rất nhiều trong android. Bởi vì nó là ViewGroup đơn giản nhất, và thời gian tính toán của nó để layout ra các view con trong nó là thấp nhất nên performence của ViewGroup này là cao nhất.

FrameLayout được định nghĩa bắt đầu bởi thẻ <FrameLayout> và thẻ đóng </FrameLayout>. Ở giữa thẻ đóng và thẻ mở chính là các view con của nó.

  <?xml version="1.0" encoding="utf-8"?>  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"      android:layout_width="match_parent"      android:layout_height="match_parent">         <!--View Child-->     </FrameLayout>

Quy tắc layout

Quy tắc layout các view con trong FrameLayout là các view sẽ nằng chồng lên nhau, view thêm vào sau sẽ nằm đè lên view nằm phía dưới. Ví dụ như sau:

  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:tools="http://schemas.android.com/tools"      android:id="@+id/FrameLayout1"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:paddingBottom="@dimen/activity_vertical_margin"      android:paddingLeft="@dimen/activity_horizontal_margin"      android:paddingRight="@dimen/activity_horizontal_margin"      android:paddingTop="@dimen/activity_vertical_margin"      tools:context="hiepsiit.com.MainActivity" >        <TextView          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:text="Hello World"          android:textColor="#2c3e50"          android:textSize="32sp" />         <TextView          android:layout_width="wrap_content"          android:layout_height="wrap_content"          android:text="Hiep Si IT"          android:textColor="#16a085"          android:textSize="32sp" />    </FrameLayout>  

Với đoạn mã trên thì "Hiep Si IT" sẽ nằm chồng lên "Hello World":

  <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"      xmlns:tools="http://schemas.android.com/tools"      android:id="@+id/FrameLayout1"      android:layout_width="match_parent"      android:layout_height="match_parent"      android:paddingBottom="@dimen/activity_vertical_margin"      android:paddingLeft="@dimen/activity_horizontal_margin"      android:paddingRight="@dimen/activity_horizontal_margin"      android:paddingTop="@dimen/activity_vertical_margin"      tools:context="hiepsiit.com.MainActivity" >       <FrameLayout          android:layout_width="match_parent"          android:layout_height="wrap_content">          <ImageView              android:layout_width="match_parent"              android:layout_height="wrap_content"              android:src="@drawable/avatar"/>             <TextView              android:layout_gravity="bottom|center"              android:layout_width="wrap_content"              android:layout_height="wrap_content"              android:text="Nguyễn Trương Minh Trí"              android:textColor="#16a085"              android:textSize="32sp" />      </FrameLayout>       </FrameLayout>  

Tên sẽ nằm trên hình ảnh

Ưu điểm

+ Là ViewGroup đơn giản nên thời gian tính toán để layout các view con nhanh.

Nhược điểm

+ Không thiết kế được cái giao diện phức tạp.


Download ví dụ


 



Cập nhật công nghệ từ Youtube tại link: https://www.youtube.com/channel/UCOxeYcvZPGf-mGLYSl_1LuA/videos
Để tham gia khóa học công nghệ truy cập link: http://thuvien.hocviendaotao.com
Mọi hỗ trợ về công nghệ email: dinhanhtuan68@gmail.com

About Học viện đào tạo trực tuyến

Xinh chào bạn. Tôi là Đinh Anh Tuấn - Thạc sĩ CNTT. Email: dinhanhtuan68@gmail.com .
- Nhận đào tạo trực tuyến lập trình dành cho nhà quản lý, kế toán bằng Foxpro, Access 2010, Excel, Macro Excel, Macro Word, chứng chỉ MOS cao cấp, IC3, tiếng anh, phần mềm, phần cứng .
- Nhận thiết kế phần mềm quản lý, Web, Web ứng dụng, quản lý, bán hàng,... Nhận Thiết kế bài giảng điện tử, số hóa tài liệu...
HỌC VIỆN ĐÀO TẠO TRỰC TUYẾN:TẬN TÂM-CHẤT LƯỢNG.
«
Next
Bài đăng Mới hơn
»
Previous
Bài đăng Cũ hơn