Android开发之相对布局

1androidx.appcompat.widget.LinearLayoutCompat是Android开发中常用的布局组件之一,它提供了强大的兼容性和布局管理能力,是构建用户界面时不可或缺的工具。

这玩意应该是说明使用哪种布局

2

<?xml version="1.0" encoding="utf-8"?>
<androidx.appcompat.widget.LinearLayoutCompat 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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
    android:gravity = "center|center_horizontal"
    tools:context=".CommonAttrActivity">

    <TextView
        android:id = "@+id/titleTv"
        android:background="#F00"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_margin="20dp"
        android:padding = "20dp"
        android:text = "我不读博士"/>


</androidx.appcompat.widget.LinearLayoutCompat>

在这里插入图片描述

3 android:layout_alignParent=“true” View在图像的左上角

在这里插入图片描述

android:layout_alignParentBottom=“true” View在图像的左下角
在这里插入图片描述

4 android:layout_alignParentRight=“true” 画面的右上角

android:layout_alignParentLeft = "true"画面的左上角

5android:layout_centerInParent = "true"屏幕的中间位置

android:layout_centerHorizontal = "true"水平居中
android:layout_centerVertical = "true"垂直居中

6

    <View
        android:id="@+id/view1"
        android:layout_centerInParent="true"
        android:layout_width = "100dp"
        android:layout_height = "100dp"
        android:background = "#F00"/>

    <View
        android:layout_alignTop = "@+id/view1"
        android:layout_width = "100dp"
        android:layout_height = "100dp"
        android:background = "#0F0"/>

这个是兄弟控件里的和view1的顶部对齐

7兄弟控件还有几种表达

android:layout_above = "@+id/view1"
android:layout_below = "@+id/view1"
android:layout_alignTop = "@+id/view1"
android:layout_alignBottom = "@+id/view1"
android:layout_alignLeft = "@+id/view1"
android:layout_alignRight = "@+id/view1"
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值