android布局

线性布局

LinearLayout

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
这是开头android="http://schemas.android.com/apk/res/android"是表示引用,方便下面的成员使用

android:layout_width="match_parent"表示宽暂满全部
android:layout_height="wrap_content"表示高占满字体内容
android:orientation="horizontal"水平排列,那么将是一个单行N列的结构
android:orientation="vertical"垂直排列,那么将是一个N行单列的结构,每一行只会有一个元素,而不论这个元素的宽度为多少
android:paddingRight="20dp"内边距
android:layout_marginRight="40dp"/>外边距
android:textColor="@color/colorRed"字体颜色,可以在values里定义
 android:textSize="@dimen/textFont"字体大小,在values里dimens里可以设定
  android:background="@color/colorPurple"TextView的背景颜色

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:orientation="horizontal"
    tools:context="myapplication.weixin.com.myapplication.MainActivity">

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hello World3"
        android:textColor="@color/colorPink"
        android:textSize="@dimen/textFont"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:background="@color/colorPurple"

        android:layout_marginRight="40dp"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:text="Hello World4"
        android:textColor="@color/colorRed"
        android:textSize="@dimen/textFont"
        android:layout_weight="1"
        android:layout_gravity="center"
        android:background="@color/colorBlue"/>

</LinearLayout

RelativeLayout

位置关系布局

特别的是子元素根据位置关系定位

首先

android:id="@+id/rel_textView1"

为每一个子元素设定唯一的ID值

android:layout_toRightOf="@id/rel_textView1"/>
把每一个子元素相对根元素的位置表示出来

Layout_toRightof="元素"在所表示元素的右边

Layout_toLeftof="元素"在所表示元素的右边


android:layout_above —— 该组件位于引用组件的上方
android:layout_below —— 该组件位于引用组件的下方

android:layout_alignParentLeft —— 该组件是否对齐父组件的左端
android:layout_alignParentRight —— 该组件是否齐其父组件的右端
android:layout_alignParentTop —— 该组件是否对齐父组件的顶部
android:layout_alignParentBottom —— 该组件是否对齐父组件的底

android:layout_centerInParent —— 该组件是否相对于父组件居中
android:layout_centerHorizontal —— 该组件是否横向居中
android:layout_centerVertical —— 该组件是否垂直居中

android:layout_alignBaseline="@id/"———表示位于ID标号空间的下标对齐

android:layout_alignStart="@id/"—— 表示和ID标号的物体一起开始

以上两种对齐方式主要应用于输入界面,两条输入线的对齐













  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值