现在的位置: 首页 > 综合 > 正文

FrameLayou和布局优化(转)

2012年09月22日 ⁄ 综合 ⁄ 共 1164字 ⁄ 字号 评论关闭

 http://android.blog.51cto.com/268543/308090

FrameLayout

     先来看官方文档的定义:FrameLayout是最简单的一个布局对象。它被定制为你屏幕上的一个空白备用区域,之后你可以在其中填充一个单一对象 — 比如,一张你要发布的图片。所有的子元素将会固定在屏幕的左上角;你不能为FrameLayout中的一个子元素指定一个位置。后一个子元素将会直接在前一个子元素之上进行覆盖填充,把它们部份或全部挡住(除非后一个子元素是透明的)。
     我的理解是,把FrameLayout当作画布canvas,固定从屏幕的左上角开始填充图片,文字等。看看示例,原来可以利用android:layout_gravity来设置位置的:
  1. <?xml version="1.0" encoding="utf-8"?> 
  2. <FrameLayout 
  3.   xmlns:android="http://schemas.android.com/apk/res/android" 
  4.   android:layout_width="fill_parent" 
  5.   android:layout_height="fill_parent" > 
  6.  
  7.     <ImageView 
  8.         android:id="@+id/image" 
  9.         android:layout_width="fill_parent"  
  10.         android:layout_height="fill_parent" 
  11.         android:scaleType="center" 
  12.         android:src="@drawable/candle" 
  13.         /> 
  14.     <TextView 
  15.         android:id="@+id/text1" 
  16.         android:layout_width="wrap_content" 
  17.         android:layout_height="wrap_content" 
  18.         android:layout_gravity="center" 
  19.         android:textColor="#00ff00" 
  20.         android:text="@string/hello" 
  21.         /> 
  22.     <Button 
  23.         android:id="@+id/start" 
  24.         android:layout_width="wrap_content" 
  25.         android:layout_height="wrap_content" 
  26.         android:layout_gravity

抱歉!评论已关闭.