Android布局学习(三)——帧布局FrameLayout

代码接着上文:《Android布局学习(二)——相对布局RelativeLayout》继续编写。

FrameLayout帧布局简单而且应用场景少,这种布局所有控件都会摆放在左上角

一、体验帧布局

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent" android:layout_height="match_parent">
    
    <TextView
        android:id="@+id/text_view"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="This is TextView"
        />
    
    <ImageView
        android:id="@+id/image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"/>

</FrameLayout>

此时项目中没有图片,于是引用了启动图
在这里插入图片描述
发现图片和文字重叠在一起

二、layout_gravity对齐方式

线性布局LinearLayout中我们记住了这个属性,这个属性在 帧布局FrameLayout中是类似的

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

    <TextView
        android:id="@+id/text_view"
        android:layout_height="wrap_content"
        android:layout_width="wrap_content"
        android:text="This is TextView"

        android:layout_gravity="left"
        />

    <ImageView
        android:id="@+id/image_view"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"

        android:layout_gravity="right"
        />

</FrameLayout>

设置了左对齐和右对齐,然后运行:
在这里插入图片描述
这种布局的应用场景蛮少的,以后再补充。

发布了156 篇原创文章 · 获赞 13 · 访问量 7239

猜你喜欢

转载自blog.csdn.net/qq_41205771/article/details/103915349