`
lyunabc
  • 浏览: 531214 次
  • 性别: Icon_minigender_2
社区版块
存档分类
最新评论

Android ApiDemos示例解析(151):Views->Layouts->RelativeLayout->1. Vertical

 
阅读更多

RelativeLayout 让子元素指定它们相对于其他元素的位置(通过ID 来指定)或相对于父布局对象。

本例使用RelativeLayout 显示三个TextView ,其中第二个TextView(id/view3)占据整个屏幕中间部分,前面我们已经介绍了如何使用LinearLayout,通过指定View的权重实现同样的效果Android ApiDemos示例解析(143):Views->Layouts->LinearLayout->3. Vertical (Padded)

本例使用RelativeLayout ,因为需要通过制定其它View作为参照物,所有子View必须定义id,其它子View通过指定参照物的id来确定其相对位置。

<RelativeLayoutxmlns:android=”http://schemas.android.com/apk/res/android”
android:layout_width=”match_parent”
android:layout_height=”match_parent”>

<!– view1 goes on top –>
<TextView
android:id=”@+id/view1″
android:background=”@drawable/red”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignParentTop=”true”
android:text=”@string/relative_layout_1_top”/>

<!– view2 goes on the bottom –>
<TextView
android:id=”@+id/view2″
android:background=”@drawable/green”
android:layout_width=”match_parent”
android:layout_height=”wrap_content”
android:layout_alignParentBottom=”true”
android:text=”@string/relative_layout_1_bottom”/>

<!– view3 stretches betweeen view1 and view2 –>
<TextView
android:id=”@+id/view3″
android:background=”@drawable/yellow”
android:layout_width=”match_parent”
android:layout_height=”0dip”
android:layout_above=”@id/view2″
android:layout_below=”@id/view1″

android:text=”@string/relative_layout_1_center”/>

</RelativeLayout>

TextView1 (id/view1) 指出其相对于父容器RelativeLayout的layout_alignParentTop为True,因此其显示在屏幕顶部。

TextView2 (id/view2) 指出其相对于父容器RelativeLayout的android:layout_alignParentBottom为True,因此其显示在屏幕底部。

TextView3(id/view3) 高度设为0,但通过android:layout_above和android:layout_below指出它和TextView1于TextView2之间的相对位置(和两个TextView上下相邻),因此TextView3占据所有剩余的中间部分。

分享到:
评论

相关推荐

    Android ApiDemos示例解析(26):App->Notification->IncomingMessage

    NULL 博文链接:https://kakukemeit.iteye.com/blog/1806388

    android apidemos示例解析

    android apidemos代码的示例解析,讲的挺全的

    Android ApiDemos apk

    Android ApiDemos apk, 包括Android presentation双屏异显 demon, App&gt;Activity&gt;Presentation

    Android ApiDemos4.4 示例解析

    最新版ApiDemos Android SDK 中带有很多例子,其中ApiDemo 详细介绍了Android 平台主要API,分成了 · App · Content · Graphics · Media · OS · Text · Views 几个大类,每个大类又分为几个小类,...

    jdk-8u202-linux-x64-demos.tar.gz

    demos :jdk-8u202-linux-x64-demos.tar.gz

    jdk-8u151-linux-i586-demos.gz

    jdk-8u151-linux-i586-demos.gz

    jdk-8u202-linux-arm64-vfp-hflt-demos.tar.gz

    demos :jdk-8u202-linux-arm64-vfp-hflt-demos.tar.gz

    最新Android apidemos

    最新Android apidemos

    FairyGUI-Unity-Plugin-3.4.0.zip

    Run demos in Assets/FairyGUI/Examples/Scenes. The UI project is in Examples-UIProject.zip, unzip it anywhere. Use FairyGUI Editor to open it. Using FairyGUI in Unity: * Place a UIPanel in scene by ...

    Android6.0 ApiDemos.apk

    从官方预览包里提取的Android6.0 ApiDemos.apk,方便安装在真机上查看实例的实际效果。

    jdk-8u231-solaris-x64-demos.tar.gz

    文件名称: jdk-8u231-solaris-x64-demos.tar.gz 文件大小: 8.43 MB (8,846,115 字节) MD5: 3b62803c4e86b40f1a83b68be7bce224 SHA1: 3aba5de2157163b949179a5b654494da05b4da9c SHA256: 774c5d41a1422d22d026eaaa39...

    Microsoft.Premium.DP-300.by-.VCEup-.82q-DEMOS.pdf

    Microsoft.Premium.DP-300.by_.VCEup_.82q-DEMOS.pdf

    Ehlib_6.1.129

    &lt;EhLib Archive&gt; \ Demos \ DBVertGridEh.SimpleDemo \ Project1.dpr compiled project: &lt;EhLib Archive&gt; \ Demos \ Bin \ DBVertGridEh.SimpleDemo.Exe * There are changes in the grids inheritance tree: ...

    LigerUI V1.1.0

    api ------------- API目录 demos ------------- 本地demos目录 lib ------------- 框架源代码目录 index.htm ------------- 主页面 loading.gif ------------- loading图标 welcome.htm ------------- 欢迎页面 ...

    Ehlib6.1.129

    &lt;EhLib Archive&gt; \ Demos \ DBVertGridEh.SimpleDemo \ Project1.dpr compiled project: &lt;EhLib Archive&gt; \ Demos \ Bin \ DBVertGridEh.SimpleDemo.Exe * There are changes in the grids inheritance tree: ...

    android的ApiDemos

    API Demos 是 Google 为了 Android 开发者所提供的一个 Android API 合集,其中包含了很多的 API 范例,同时遵循了良好的代码规范,是一个值得开发者研究和学习的典型。android的ApiDemos,需要解压缩后使用。

    red5-1.0.0-webapps-demos.zip

    r下载后,解压,把解压后的文件直接放入到red5webaaps下

    sciter-sdk-4.0.0.7

    vertical-align fix. [win] fix of WM_SETTINGCHANGE handling for some types of windows. [css] Fix of hsl/hsv() color transforms: samples/css++/hsl-colors.htm r5010 regression (forcing padding, margin ...

    android ApiDemos

    android APIdemos,android 源码简单使用demos

    dwr包.rar dwr.jar engine.js util.js dwr-noncla.jar readme.txt

    WAR File: dwr.war (4.62Mb) Demos/Examples of what DWR can do Sources: dwr-3.0.0.116.rc1-src.zip (71Mb) See also the sources from SVN Non-CLA JAR: dwr-noncla.jar (15.8kb) Code that we don't ...

Global site tag (gtag.js) - Google Analytics