天天看點

[Android新手學習筆記20]-FrameLayout幀布局

應用場景較少,碎片會使用。

  1. <?xml version="1.0" encoding="utf-8"?>
  2. <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
  3.    android:layout_width="match_parent"
  4.    android:layout_height="match_parent">
  5.    <Button
  6.        android:id="@+id/button1"
  7.        android:text="Button"
  8.        android:textAllCaps="false"
  9.        android:layout_width="wrap_content"
  10.        android:layout_height="wrap_content" />
  11.    <TextView
  12.        android:id="@+id/text_view"
  13.        android:text="TextView很長很長"
  14.        android:layout_width="wrap_content"
  15.        android:layout_height="wrap_content" />
  16. </FrameLayout>

這種布局會重疊在左上角擺放。可以通過android:layout_gravity來控制對齊。