Android界面佈局(3)—相對佈局和絕對佈局

相對佈局

        相對佈局(RelativeLayout)是一種很是靈活的佈局方式,可以經過指定界面元素與其餘元素的相對位置關係,肯定界面中全部元素的佈局位置。相對佈局和線性佈局有着共同的優勢,可以最大程度保證在各類屏幕類型的手機正確的顯示界面佈局。android

相對佈局的各類屬性

相對於兄弟元素佈局

  • android:layout_below="@id/aaa":在指定View的下方
  • android:layout_above="@id/xxx":在指定View的上方
  • android:layout_toLeftOf="@id/bbb":在指定View的左邊
  • android:layout_toRightOf="@id/cccc":在指定View的右邊

相對於父元素spa

  • android:layout_alignParentLeft="true":在父元素內左邊
  • android:layout_alignParentRight="true":在父元素內右邊
  • android:layout_alignParentTop="true":在父元素內頂部
  • android:layout_alignParentBottom="true":在父元素內底部

對齊方式3d

  • android:layout_centerInParent="true":居中佈局
  • android:layout_centerVertical="true":水平居中佈局
  • android:layout_centerHorizontal="true":垂直居中佈局
  • android:layout_alignTop="@id/xxx":與指定View的上邊界一致
  • android:layout_alignBottom="@id/xxx":與指定View下邊界一致
  • android:layout_alignLeft="@id/xxx":與指定View的左邊界一致
  • android:layout_alignRight="@id/xxx":與指定View的右邊界一致

間隔code

  • android:layout_marginBottom=""; 離某元素底邊緣的距離
  • android:layout_marginLeft=""; 離某元素左邊緣的距離
  • android:layout_marginRight ="";離某元素右邊緣的距離
  • android:layout_marginTop=""; 離某元素上邊緣的距離
  • android:layout_paddingBottom=""; 離父元素底邊緣的距離
  • android:layout_paddingLeft=""; 離父元素左邊緣的距離
  • android:layout_paddingRight ="";離父元素右邊緣的距離
  • android:layout_paddingTop=""; 離父元素上邊緣的距離

— — — — — — — — 華麗的分割線 — — — — — — — — xml

絕對佈局

        絕對佈局(AbsoluteLayout)能經過指定的界面元素的座標位置,來肯定用戶界面的總體佈局。絕對佈局是一種不推薦使用的佈局(下降了界面佈局對不一樣類型和尺寸屏幕的適應能力)。每個界面控件都要指定座標 (X,Y)。class

<TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="0dp"
        android:layout_x="89dp"
        android:layout_y="93dp"
        android:text="Small Text"
        android:textAppearance="?android:attr/textAppearanceSmall" />
相關文章
相關標籤/搜索