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萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章