Mình đang xây dựng nhóm "anh Thầy & Đồng bọn (Hỏi đáp, chia sẻ kiến thức)" mục đích để các bạn có một nơi giao lưu trao đổi.
Đội MOD của group và mọi người sẽ hỗ trợ bạn ngay lập tức.
Join ở đây nè: https://www.facebook.com/groups/anhthayvadongbon
Lượt xem: 2118 lượt xem
1. Tổng quan về layout trong Android
2. LinearLayout
android:orientation="horizontal"
android:orientation="vertical"
Giá trị | Thuộc tính |
---|---|
center | Căn ở giữa |
top | Ở phần trên |
bottom | Phần dưới |
center_horizontal | Ở giữa theo chiều ngang |
center_vertical | Ở giữa theo chiều đứng |
left | Theo cạnh trái |
right | Theo cạnh phải |
bottom | Cạnh dưới |
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:weightSum="5"
android:gravity="center"
tools:context=".View">
<Button
android:layout_weight="1"
android:textSize="30dp"
android:text="01"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_weight="1"
android:textSize="30dp"
android:text="02"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_weight="1"
android:textSize="30dp"
android:text="03"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_weight="1"
android:textSize="30dp"
android:text="04"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
<Button
android:layout_weight="1"
android:textSize="30dp"
android:text="05"
android:layout_width="match_parent"
android:layout_height="match_parent"/>
</LinearLayout>
3. Relativelayout
Giá trị | Ý nghĩa |
---|---|
center | Căn ở giữa |
top | Ở phần trên |
bottom | Phần dưới |
center_horizontal | Ở giữa theo chiều ngang |
center_vertical | Ở giữa theo chiều đứng |
left | Theo cạnh trái |
right | Theo cạnh phải |
bottom | Cạnh dưới |
Thuộc tính | Ý nghĩa |
---|---|
android:layout_alignParentBottom | true căn thẳng cạnh dưới view con với cạnh dưới View cha |
android:layout_alignParentLeft | true căn thẳng cạnh trái view con với cạnh trái View cha |
android:layout_alignParentRight | true căn thẳng cạnh phải view con với cạnh phải View cha |
android:layout_alignParentTop | true căn thẳng cạnh trên view con với cạnh trên View cha |
android:layout_centerInParent | true căn view con vào giữa View cha |
android:layout_centerHorizontal | true căn view con vào giữa View cha theo chiều ngang |
android:layout_centerVertical | true căn view con vào giữa View cha theo chiều đứng |
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:gravity="center"
tools:context=".View">
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text=" Hop 1"
android:textColor="@android:color/black"
android:id="@+id/hop1"
android:textSize="10pt"
android:textAlignment="center"
android:background="#D32F2F"
/>
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text=" Hop 2"
android:textColor="@android:color/black"
android:id="@+id/hop2"
android:textSize="10pt"
android:textAlignment="center"
android:layout_toRightOf="@+id/hop1"
android:background="#FFEB3B"
/>
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text=" Hop 3"
android:textColor="@android:color/black"
android:id="@+id/hop3"
android:background="#FFAB40"
android:textSize="10pt"
android:textAlignment="center"
android:layout_below="@+id/hop1"
/>
<TextView
android:layout_width="150dp"
android:layout_height="50dp"
android:text="Hop 4"
android:textColor="@android:color/black"
android:id="@+id/hop4"
android:textSize="10pt"
android:textAlignment="center"
android:background="#E040FB"
android:layout_below="@+id/hop2"
android:layout_toRightOf="@+id/hop3"
/>
</RelativeLayout>
4. GridLayout
GridLayout trong Android
<?xml version="1.0" encoding="utf-8"?>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_gravity="center"
android:orientation="vertical"
android:id="@+id/gridlayout_demo"
android:gravity="center"
android:columnCount="2"
android:rowCount="2"
tools:context=".View">
</GridLayout>
<GridLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:id="@+id/GridLayout1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:columnCount="3"
android:orientation="horizontal"
android:rowCount="3" >
<Button
android:id="@+id/button1"
android:layout_gravity="left|top"
android:text="@string/button_name" />
<Button
android:id="@+id/button4"
android:layout_column="0"
android:layout_gravity="left|top"
android:layout_row="2"
android:text="@string/button_name" />
<Button
android:id="@+id/button5"
android:layout_width="213dp"
android:layout_column="1"
android:layout_columnSpan="2"
android:layout_gravity="fill_horizontal|fill_vertical"
android:layout_row="2"
android:text="@string/button_name" />
<Button
android:id="@+id/button2"
android:layout_column="2"
android:layout_gravity="left|top"
android:layout_row="0"
android:text="@string/button_name" />
<Button
android:id="@+id/button3"
android:layout_column="2"
android:layout_gravity="right|top"
android:layout_row="0"
android:text="@string/button_name" />
</GridLayout>
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Trang web này không lưu trữ bất kỳ tệp (files) nào trên máy chủ (server). Chúng tôi chỉ lập chỉ mục và liên kết đến nội dung được cung cấp bởi các trang web khác. Vui lòng liên hệ với các nhà cung cấp nội dung để xóa nội dung bản quyền nếu có và gửi email cho chúng tôi, chúng tôi sẽ xóa các liên kết hoặc nội dung có liên quan ngay lập tức.
Bạn có muốn xác nhận hoàn thành bài học này không?