目录
三、权重(weight)
一、介绍(LinearLayout)
- 只能在横线或竖线放置,默认横线放置
- 容易对齐,应用在登录界面
二、常用属性
- orientation 控制横线放置还是竖线放置
horizontal,横线放置
vertical,竖线放置 - gravity
针对组件
可以使用|多个参数组合
android:gravity="center|center_horizontal"
- layout_gravity
layout控件本身 - width,heigh,id,background,和相对布局的一样用法
三、权重(weight)
把布局平均分
代码理解,实现
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_shopping_menu"
tools:context=".MainActivity" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="70dp"
android:layout_centerInParent="true"
android:background="#ff0000"
>
<LinearLayout
android:layout_weight="1"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#00ff00"
></LinearLayout>
<LinearLayout
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="70dp"
android:background="#0000ff"
></LinearLayout>
</LinearLayout>
</RelativeLayout>
四、分割线
new一个xml
设置形状,大小,宽度,颜色
使用:设置divider,dividePadding(内边距),showDividers
<?xml version="1.0" encoding="utf-8"?>
<shape xmlns:android="http://schemas.android.com/apk/res/android"
android:shape="line"
>
<size
android:width="200dp"
android:height="2dp"
/>
<stroke
android:color="#000000"
/>
</shape>
android:divider="@drawable/fg"
android:dividerPadding="2dp"
android:showDividers="middle|end"
五、制作一个页面(登录)
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:background="@drawable/bg_shopping_menu"
tools:context=".MainActivity" >
<LinearLayout
android:orientation="horizontal"
android:layout_width="300dp"
android:layout_height="70dp"
android:layout_centerInParent="true"
>
<LinearLayout
android:orientation="vertical"
android:layout_weight="2"
android:layout_width="0dp"
android:layout_height="70dp"
>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="账号"
android:textSize="25dp"
android:gravity="center"
/>
<TextView
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
android:text="密码"
android:textSize="25dp"
android:gravity="center"
/>
</LinearLayout>
<LinearLayout
android:orientation="vertical"
android:layout_weight="5"
android:layout_width="0dp"
android:layout_height="70dp"
android:divider="@drawable/fg"
android:dividerPadding="2dp"
android:showDividers="middle|end"
>
<EditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
/>
<EditText
android:layout_weight="1"
android:layout_width="match_parent"
android:layout_height="0dp"
/>
</LinearLayout>
</LinearLayout>
</RelativeLayout>
师承上官可编程 —— 陈立臣