推荐当贝市场

 找回密码
 立即注册

QQ登录

只需一步,快速开始

查看: 16851|回复: 0

[教程] 第五讲:用户界面 View(一)

[复制链接]
发表于 2013-8-28 16:19 | 显示全部楼层 |阅读模式
669
本节内容:
什么是View   
常用Layout介绍:FrameLayout, LinearLayout
点此下载:
  
二、常用Layout介绍
ViewGroup是个特殊的View,它继承于Android.view.View。它的功能就是装载和管理下一层的View对象或ViewGroup对象,也就说他是一个容纳其它元素的的容器。ViewGroup是布局管理器(layout)及view容器的基类。 ViewGroup中,还定义了一个嵌套类ViewGroup.LayoutParams。这个类定义了一个显示对象的位置、大小等属性,view通过LayoutParams中的这些属性值来告诉父级,它们将如何放置。
  
ViewGroup是一个抽象类,所以真正充当容器的是他的子类们。我们在这里将介绍 帧布局FrameLayout,线性布局LinearLayout,绝对布局AbsoluteLayout,相对布局RelativeLayout,表格布局TableLayout等几个常用布局,大约要分3讲讲完。
1、帧布局 FrameLayout:
是最简单的一个布局对象。在他里面的的所有显示对象爱你过都将固定在屏幕的左上角,不能指定位置,但允许有多个显示对象,只是后一个会直接覆盖在前一个之上显示,会把前面的组件部分或全部挡住。下图的例子里,FrameLayout中放了3个ImageView组件,第一个是蓝色的,第二个是绿色的,第三个是树状图(透明的png格式)。ImageView就相当于Html中的img标签,接下来会讲到这个组件。
下面看一个FrameLayout的例子:
   
   
  1. <?xml version=”1.0″ encoding=”utf-8″?><FrameLayout android:id=”@+id/FrameLayout01″   
    android:layout_width=”fill_parent” android:layout_height=”fill_parent”   
    xmlns:android=”http://schemas.android.com/apk/res/android”><ImageView android:id=”@+id/ImageView01″ android:src=”@drawable/p1″   
    android:layout_width=”wrap_content” android:layout_height=”wrap_content”></ImageView><ImageView android:id=”@+id/ImageView02″ android:src=”@drawable/p2″   
    android:layout_width=”wrap_content” android:layout_height=”wrap_content”></ImageView><ImageView android:id=”@+id/ImageView03″ android:src=”@drawable/p3″   
    android:layout_width=”wrap_content” android:layout_height=”wrap_content”></ImageView></FrameLayout>
复制代码
  
   
完整的代码在PPT附带的目录中,需要的朋友可以留言向我索要。
     
(FrameLayout的显示效果)
2、线性布局 LinearLayout:
线性布局是所有布局中最常用的类之一,也是RadioGroup, TabWidget, TableLayout, TableRow, ZoomControls类的父类。LinearLayout可以让它的子元素垂直或水平的方式排成一行(不设置方向的时候默认按照垂直方向排列)。
下面看一个LinearLayout的例子:别被例子的长度吓住,仔细看一下其实就是一个LinearLayout中放5个TextView标签而已,TextView相当于Html标签中的Label。
   
   
  1. <?xml version=”1.0″ encoding=”utf-8″?>   
    <LinearLayout xmlns:android=”http://schemas.android.com/apk/res/android”   
    android:orientation=”vertical”   
    android:layout_width=”fill_parent”   
    android:layout_height=”fill_parent”   
    android:gravity=”center_horizontal”   
    >   
    <TextView   
    android:layout_width=”fill_parent”   
    android:layout_height=”wrap_content”   
    android:text=”给小宝宝起个名字:”   
    android:textSize=”20px”   
    android:textColor=”#0ff”   
    android:background=”#333″/>   
    <TextView   
    android:layout_width=”wrap_content”   
    android:layout_height=”wrap_content”   
    android:text=”遥遥是男孩的小名”   
    android:textSize=”20px”   
    android:textColor=”#0f0″   
    android:background=”#eee”   
    android:layout_weight=”3″   
    />   
    <TextView   
    android:layout_width=”wrap_content”   
    android:layout_height=”wrap_content”   
    android:text=”瑶瑶是女孩的小名”   
    android:textColor=”#00f”   
    android:textSize=”20px”   
    android:background=”#ccc”   
    android:layout_weight=”1″   
    /><TextView   
    android:layout_width=”fill_parent”   
    android:layout_height=”wrap_content”   
    android:text=”海因是男孩的大名”   
    android:textColor=”#f33″   
    android:textSize=”20px”   
    android:background=”#888″   
    android:layout_weight=”1″   
    />   
    <TextView   
    android:layout_width=”fill_parent”   
    android:layout_height=”wrap_content”   
    android:text=”海音是女孩的大名”   
    android:textColor=”#ff3″   
    android:textSize=”20px”   
    android:background=”#333″   
    android:layout_weight=”1″   
    />   
    </LinearLayout>
复制代码
  
   
下图是显示效果:
  
好吧下次再讲。
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

站长推荐上一条 /2 下一条

Archiver|小黑屋|新帖|标签|软件|Sitemap|ZNDS智能电视网 ( 苏ICP备2023012627号 )

GMT+8, 2026-11-6 22:25 , Processed in 0.027547 second(s), 7 queries , Redis On.

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表