您的位置:首页 > 职场人生

.Net程序员玩转Android开发---(9)绝对布局AbsoluteLayout

2014-11-19 11:29 417 查看
绝对布局AbsoluteLayout类似于.NET中Winform的布局方式,以窗体左上角为坐标点,向右向下延伸. 由于绝对布局每个控件的位置是固定的,不能随着屏幕的大小改变而改变,所以在不同设备上运行出来的效果不同,所以这种布局方式使用的比较少。

绝对布局AbsoluteLayout中的控件有两个重要属性layout_x和layout_y分别用来设置控件的绝对位置。

下面我们看下这个例子布局的效果



<?xml version="1.0" encoding="utf-8"?>
<AbsoluteLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent" >

<ImageView
android:id="@+id/imageView1"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_x="0dp"
android:layout_y="3dp"
android:src="@raw/pad" />

<TextView
android:id="@+id/textView2"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_x="110dp"
android:layout_y="78dp"
android:text="商品颜色:白色" />

<TextView
android:id="@+id/textView2"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_x="110dp"
android:layout_y="47dp"
android:text="商品价格:$19" />

<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_x="110dp"
android:layout_y="16dp"
android:text="商品名称:Ipad Air" />

<TextView
android:id="@+id/textView1"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_x="0dp"
android:layout_y="118dp"
android:background="#EEE8CD"
android:text="" />

<ImageView
android:id="@+id/ImageView01"
android:layout_width="96dp"
android:layout_height="96dp"
android:layout_x="9dp"
android:layout_y="137dp"
android:src="@raw/pad" />

<TextView
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_x="118dp"
android:layout_y="144dp"
android:text="商品名称:Ipad Air" />

<TextView
android:id="@+id/TextView01"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_x="118dp"
android:layout_y="206dp"
android:text="商品颜色:白色" />

<TextView
android:id="@+id/TextView01"
android:layout_width="120dp"
android:layout_height="wrap_content"
android:layout_x="118dp"
android:layout_y="176dp"
android:text="商品价格:$19" />

<TextView
android:id="@+id/TextView02"
android:layout_width="match_parent"
android:layout_height="3dp"
android:layout_x="2dp"
android:layout_y="261dp"
android:background="#EEE8CD" />

</AbsoluteLayout>



内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: