Android的框架布局:FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Layout_FrameLayout">

    <FrameLayout
        android:id="@+id/myframe"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="199dp"
        tools:layout_editor_absoluteY="179dp">
        <TextView
            android:layout_height="200dp"
            android:layout_width="200dp"
            android:background="#8F96BF"
            />

    </FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

效果

再添加一个

<TextView android:layout_height="200dp" android:layout_width="200dp" android:background="#8F96BF" />

可以看到效果是这个样子的,感觉上是没有什么变化的,但其实是两个View叠加到了一起。

我们可以把叠加的那个大小改变一下,这样就可以很清楚的看到。

<TextView
    android:layout_height="100dp"
    android:layout_width="100dp"
    android:background="#8F96BF"
    />

tip:尽量使用dp作为空间大小的单位,sp作为文字相关大小的单位。

我们再加上<ImageView
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:src="@drawable/hhh"

    />
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".Layout_FrameLayout">

    <FrameLayout
        android:id="@+id/myframe"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        tools:layout_editor_absoluteX="199dp"
        tools:layout_editor_absoluteY="179dp">
        <TextView
            android:layout_height="200dp"
            android:layout_width="200dp"
            android:background="#8F96BF"
            />
        <TextView
            android:layout_height="100dp"
            android:layout_width="100dp"
            android:background="#fff"
            android:text="西安科技大学"
            android:textColor="#f00"
            android:textSize="20sp"
            />
        <ImageView
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:src="@drawable/hhh"

            />

    </FrameLayout>
</androidx.constraintlayout.widget.ConstraintLayout>

android:layout_gravity="right"

扫描二维码关注公众号,回复: 14682350 查看本文章

猜你喜欢

转载自blog.csdn.net/a15929748502/article/details/110731064