乐读文学

Android从入门到精通

乐读文学 > 科普学习 > Android从入门到精通

第20页

书籍名:《Android从入门到精通》    作者:明日科技




android:layout_height="fill_parent"  />





(4)在第3个表格行中添加具体的内容。首先添加一个水平方向的线性布局管理器,然后在该布局管理器中添加一个ImageView组件和一个TextView组件,并设置这两个组件及线性布局管理器的左外边距,最后设置TextView组件垂直居中显示。具体代码如下:




android:id="@+id/linearLayout5"



android:layout_height="fill_parent"



android:layout_weight="1"



android:layout_marginLeft="20px">






android:src="@drawable/email"



android:id="@+id/imageView8"



android:layout_marginLeft="20px"



android:layout_width="wrap_content"



android:layout_height="fill_parent"  />






android:text="电子邮件"



android:layout_marginLeft="20px"



android:gravity="center_vertical"



style="@style/text"



android:layout_width="wrap_content"



android:layout_height="fill_parent"  />





运行本实例,将显示如图3.13所示的运行结果。



图3.13 布局分类显示的快捷工具栏

3.2.6 范例2:布局个性游戏开始界面

例3.10   在Eclipse中创建Android项目,名称为3.10,应用线性布局和相对布局实现个性游戏开始界面。(实例位置:光盘\TM\sl\3\3.10)

(1)修改新建项目的res\layout目录下的布局文件main.xml,将默认添加的布局代码中的TextView组件删除,然后添加一个ImageView组件,用于显示顶部图片,并设置其缩放方式为保持纵横比缩放,让图片完全覆盖ImageView。修改后的代码如下:








android:orientation="vertical"



android:layout_width="fill_parent"



android:layout_height="fill_parent">










android:layout_height="wrap_content"



android:scaleType="centerCrop"



android:layout_weight="1"



android:src="@drawable/top"  />





(2)在ImageView组件的下方添加一个相对布局管理器,用于显示控制按钮。在该布局管理器中添加5个ImageView组件,并且第1个ImageView组件显示在相对布局管理器的中央,其他4个环绕在第1个组件的四周,具体代码如下:








android:layout_height="wrap_content"



android:background="@drawable/bottom"



android:id="@+id/relativeLayout1"



android:layout_width="match_parent">










android:layout_height="wrap_content"



android:id="@+id/imageButton0"



android:src="@drawable/in"



android:layout_centerlnParent="true"/>










android:layout_height="wrap_content"



android:id="@+id/imageButton1"



android:src="@drawable/setting"



android:layout_above="@+id/imageButton0"



android:layout_alignRight="@+id/imageButton0"  />










android:layout_height="wrap_content"



android:id="@+id/imageButton2"



android:src="@drawable/exit"



android:layout_below="@+id/imageButton0"



android:layout_alignLeft="@+id/imageButton0"  />










android:layout_height="wrap_content"



android:id="@+id/imageButton3"



android:src="@drawable/help"



android:layout_toLeftOf="@+id/imageButton0"



android:layout_alignTop="@+id/imageButton0"  />