Android五大布局与实际应用详解

2019-12-10 18:54:44王旭

显示结果:

Android五大布局与实际应用详解

这是一个顶部布局样式,在很多app中我们会考虑使用样式基本相同的顶部布局来统一风格。这只是一个简单的布局,包含一个Title以及取消按钮(这里用的TextView代替),相对于其他几个布局控件,RelativeLayout在这里使用起来更简单也更合理。首先设置RelativeLayout的高度,再设置Title的android:layout_centerInParent=”true”显示在中央,最后设置取消按钮的两个属性垂直居中android:layout_centerVertical=”true”和右部对齐android:layout_alignParentRight=”true”。

四、AbsoluteLayout

绝对布局也叫坐标布局,指定控件的绝对位置,简单直接,直观性强,但是手机屏幕尺寸差别较大,适应性差,Android 1.5已弃用,可以用RelativeLayout替代。

AbsoluteLayout实现布局代码:

<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://www.easck.com/apk/res/android"
  android:layout_width="match_parent" android:layout_height="match_parent">

  <ImageView
    android:layout_width="100dip"
    android:layout_height="120dip"
    android:layout_x="150dip"
    android:layout_y="40dip"
    android:src="@drawable/android_logo"/>

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="100dip"
    android:layout_y="150dip"
    android:text="上一张"/>

  <Button
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:layout_x="200dip"
    android:layout_y="150dip"
    android:text="下一张"/>

  </AbsoluteLayout>

显示效果:

Android五大布局与实际应用详解