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>

image

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>

image

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>

image

更多相关文章

  1. Android Chronometer控件开发
  2. Android 控件一 TextView
  3. Android 控件二 Button
  4. Android中的windowSoftInputMode属性详解
  5. Android属性动画AnimatorSet源码简单分析
  6. Android控件TextView中ellipsize属性(设置当文字长度超过textview

随机推荐

  1. Android开发中怎样调用系统Email发送邮件
  2. 用kotlin打印出漂亮的android日志(三)—
  3. android 修改窗体标题的字体式样和…
  4. Android(安卓)Matrix Riot (IM)SDK 集成专
  5. 实现Android简单动画旋转案例源码
  6. Android中通过xml给布局添加边框
  7. 安装Termux的手机上运行Python
  8. Android侧滑控件之DrawerLayout的使用
  9. Android获取控件宽高的几种方式
  10. Android(安卓)为所有app开放 系统app才能