ZNDS智能电视网 推荐当贝市场

TV应用下载 / 资源分享区

软件下载 | 游戏 | 讨论 | 电视计算器

综合交流 / 评测 / 活动区

交流区 | 测硬件 | 网站活动 | Z币中心

新手入门 / 进阶 / 社区互助

新手 | 你问我答 | 免费刷机救砖 | ROM固件

查看: 15939|回复: 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>
复制代码
  
   
完整的代码在AI.com/ppt" target="_blank" class="relatedlink">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>
复制代码
  
   
下图是显示效果:
  
好吧下次再讲。

上一篇:第十七讲:对话框 Android Dialog
下一篇:第四讲:Activity入门指南
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

关闭

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

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

网络信息服务信用承诺书 | 增值电信业务经营许可证:苏B2-20221768 丨 苏公网安备 32011402011373号

GMT+8, 2026-8-2 14:18 , Processed in 0.063242 second(s), 14 queries , Redis On.

Powered by Discuz!

监督举报:report#znds.com (请将#替换为@)

© 2007-2026 ZNDS.Com

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