3 RelativeLayout

子控件的位置是相对兄弟控件或父控件的位置而决定的。ViewA的位置相对于ViewB来决定,要保证B出现在A之前。

属性名称 属性说明
android:layout_centerHorizontal 当前控件位于父控件的横向中间位置
android:layout_centerVertical 当前控件位于父控件的纵向中间位置
android:layout_centerParent 当前控件位于父控件的纵横向中间位置
android:layout_alignParentBottom 当前控件低端与父控件的低端对齐
android:layout_alignParentLeft 当前控件左端与父控件的左端对齐
android:layout_alignParentRight 当前控件右端与父控件的右端对齐
android:layout_alignParentTop 当前控件上端与父控件的上端对齐
android:layout_alignWithParentIfMissing 参照控件不存在或不可见时参照父控件
android:layout_toRightOf 使当前控件位于给出id控件的右侧
android:layout_toLeftOf
android:layout_above
android:layout_below
android:layout_alignTop
android:layout_alignBottom
android:layout_alignLeft
android:layout_alignRight
android:layout_marginLeft 当前控件左侧的留白
android:layout_marginRight
android:layout_marginTop
android:layout_marginBottom

relavitelayout.xml

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent" android:layout_height="fill_parent">
<ImageView android:id="@+id/iv01" android:background="@drawable/img01"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_centerHorizontal="true" />
<ImageView android:id="@+id/iv02" android:background="@drawable/img02"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_toRightOf="@id/iv01" android:layout_alignTop="@id/iv01" />
<ImageView android:id="@+id/iv03" android:background="@drawable/img03"
android:layout_width="wrap_content" android:layout_height="wrap_content"
android:layout_below="@id/iv01" android:layout_alignLeft="@id/iv01" />
</RelativeLayout>

4 FrameLayout

在FrameLayout中,子控件是通过栈来绘制的,所有后添加的子控件会被绘制在上层

属性名称 对应方法 描述
android:foreground setForeground(Drawable) 设置绘制在所有控件之上
android:foregroundGravity setForegroundGravity(int) 设置绘制在所有子控件之上内容的gravity属性

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<TextView android:id="@+id/big" android:text="大" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="60px"
android:textColor="@drawable/white" />
<TextView android:text="中" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="40px"
android:textColor="@drawable/darkgray" />
<TextView android:text="小" android:layout_width="wrap_content"
android:layout_height="wrap_content" android:textSize="20px"
android:textColor="@drawable/abc" />
</FrameLayout>

5 AbsoluteLayout

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent" android:layout_height="match_parent">
<ImageView android:layout_height="wrap_content" android:src="@drawable/img01"
android:id="@+id/imageView1" android:layout_width="wrap_content"
android:layout_x="57dip" android:layout_y="41dip"></ImageView>
<ImageView android:layout_height="wrap_content" android:src="@drawable/img02"
android:id="@+id/imageView2" android:layout_width="wrap_content"
android:layout_x="174dip" android:layout_y="38dip"></ImageView>
<TextView android:layout_height="wrap_content" android:text="TextView"
android:layout_x="98dip" android:id="@+id/textView1"
android:layout_width="wrap_content" android:layout_y="122dip"></TextView>
<Button android:layout_height="wrap_content" android:id="@+id/button1"
android:layout_x="93dip" android:text="Button" android:layout_width="wrap_content"
android:layout_y="173dip"></Button>
</AbsoluteLayout>

更多相关文章

  1. android LocationManager的使用
  2. Kotlin 中Butterknife 和Android(安卓)中使用butterknife
  3. Launcher的启动过程
  4. @+id/android:list"和"@android:id/list"的区别
  5. android中退出当前应用程序的四种方法
  6. 浅谈Android五大布局
  7. 布局中文件中【控件间距参数详解以及单位选择】
  8. Android(安卓)Chronometer控件开发
  9. Android(安卓)Layout XML属性

随机推荐

  1. php实现无限级评论功能
  2. php文件锁产生的问题和解决方案(一个真实
  3. php扩展安装不生效问题怎么解决?
  4. 神操作之实现PHP跳转
  5. php下载网络图片常用的三个方法总结
  6. PHP中100个最常用的函数
  7. PHP Swoole 基本使用
  8. js php实现无刷新下载功能
  9. PHP测试框架PHPUnit基本使用
  10. PHP会话控制:cookie和session区别与用法深