Android布局控件的继承关系
常用属性
宽高
android:layout_width=“30dp”/“match_parent”/“wrap_content”
android:layout_height=“30dp”
盒子模型
padding:内边距
margin:外边距
重力
gravity:center 上下左右(布局设置)
layout_gravity:居中 上下左右(组件设置)
线性布局
常用属性:
方向:orientation (horizontal水平 vertical垂直)
权重:配合宽,高(宽高其中一个用0dp)
相对布局
特点:
有两种相对关系:相对父容器(7个属性 3个居中center 4个对齐align)
相对兄弟容器控件(8个属性 4个位置layout 4个对齐align)
帧布局 FrameLayout
特点:层层叠加覆盖
网格布局 GridLayout
特点:指定行列
常用属性:
行数:android:rowCount=“6”
列数:android:columnCount=“4”
跨列数:layout_columnSpan=“2”
跨行数:layout_rowSpan=“2”
列权重:layout_columnWeight=“1”
行权重:layout_rowWeight=“1”
代码实现
// An highlighted block
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1.2">
<LinearLayout
android:layout_width="0dp"
android:layout_height="match_parent"
android:layout_weight="1"
android:background="#4688BD"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/t11" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="P2P活期账本"
android:textColor="#fff"
android:textSize="30dp"
android:layout_marginLeft="50dp"/>
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:src="@mipmap/t22"
android:layout_marginLeft="60dp"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.7"
android:orientation="horizontal">
<ImageView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:scaleType="fitXY"
android:src="@mipmap/guang" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:layout_weight="1.2"
android:orientation="horizontal">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/tozi" />
<ImageView
android:layout_width="wrap_content"
android:layout_height="match_parent"
android:layout_marginLeft="140dp"
android:src="@mipmap/xiangmu" />
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="0.8">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@mipmap/changping"
android:scaleType="fitXY"/>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1.2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/tp1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="星火钱包(星火X100)"
android:textSize="18dp"
android:layout_marginTop="15dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="昨日收益"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="待收总额"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="0dp"
android:orientation="horizontal"
android:layout_weight="1.2">
<ImageView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:src="@mipmap/tp1"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="星火钱包(星火X100)"
android:textSize="18dp"
android:layout_marginTop="15dp"/>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="昨日收益"/>
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="0"/>
</LinearLayout>
<LinearLayout
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:orientation="vertical">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="待收总额"/>
<TextView
android:layout_width="wrap_content"
android:layout_height