AbsoluteLayout和FrameLayout的学习

1.AbsoluteLayout

           AbsoluteLayout绝对布局,指定子控件的xy精确座标的布局,绝对布局缺乏灵活性,在没有决对定位的情况下相比其他类型的布局更难维护。这种布局方式不被推荐。

          

代码:

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

    <TextView
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:background="#aa0000"
        android:layout_x="10dp"
        android:layout_y="10dp"
        android:text="@string/hello" />

</AbsoluteLayout>


2.FrameLayout

         FrameLayout框架布局,所有添加到这个布局中的视图以层叠的方式显示。第一个添加的组件放到最底层,最后添加到框架显示在最上面。上一层的会覆盖下一层的控件。

      


代码:

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

    <TextView
        android:layout_width="320dp"
        android:layout_height="320dp"
        android:layout_gravity="center"
        android:background="#000011"
        />
    
    <TextView
        android:layout_width="280dp"
        android:layout_height="280dp"
        android:layout_gravity="center"
        android:background="#004433"
        />
    
    <TextView
        android:layout_width="240dp"
        android:layout_height="240dp"
        android:layout_gravity="center"
        android:background="#00aa00"
        />
    
    <TextView
        android:layout_width="200dp"
        android:layout_height="200dp"
        android:layout_gravity="center"
        android:background="#00dd00"
        />
    
</FrameLayout>


发布了18 篇原创文章 · 获赞 13 · 访问量 5万+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章