Android代码使用framlayout
时间: 2024-05-01 17:20:57 浏览: 78
FrameLayout 是一个最简单的布局,它只是简单地将所有子视图堆叠在一起。在 FrameLayout 中,每一个子视图都是以 Z 轴的方式叠放,后添加的子视图会覆盖之前添加的子视图。
以下是一个使用 FrameLayout 布局的 Android 代码示例:
<FrameLayout
android:layout_width="match_parent"
android:layout_height="match_parent">
<ImageView
android:id="@+id/imageView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/my_image" />
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="Hello World!"
android:textSize="24sp"
android:textColor="@android:color/white"
android:layout_gravity="center" />
</FrameLayout>
在这个示例中,一个 ImageView 和一个 TextView 被添加到 FrameLayout 中。ImageView 显示一个图像,TextView 显示一个字符串。由于 TextView 后添加,所以它会出现在 ImageView 的上面。可以使用 android:layout_gravity 属性来指定 TextView 在 FrameLayout 中的位置,这里使用了 center 来将 TextView 居中对齐。
相关推荐















