android布局

来源:互联网 发布:明星吸毒 知乎 编辑:程序博客网 时间:2024/06/05 20:05

线性布局

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
原创粉丝点击