【Android】常用基础布局

news2024/9/23 5:31:39

布局是一种可用于放置很多控件的容器,它可以按照一定的规律调整内部控件的位置,从而编写出精美的界面,布局内不单单可以放控件,也可以嵌套布局,这样可以完成一些复杂的界面,下面就来认识一些常用的布局吧。

线性布局

  1. 名称:LinearLayout,这个布局会将它所包含的控件在线性方向上依次排列

  2. 属性:android:orientation这个属性就规定了是在竖直方向上还是水平方向上,当为vertical时,规定的排列方向就为竖直方向;当为horizontal时,控件就会在水平方向上排列

  3. 设置一个主活动,并修改其xml中的代码,在这个活动里面加入三个按钮控件,此时设置为竖直方向:

<LinearLayout 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"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_1"
        android:text="Button1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_2"
        android:text="Button2"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_3"
        android:text="Button3"/>

</LinearLayout>

此时使用的是android:orientation="vertical"即竖直方向,因此运行结果为:

在这里插入图片描述

但如果改为android:orientation="horizontal"即为水平方向,即三个按钮水平排列在第一行

注意:如果排列方式为horizontal,内部控件绝不能将宽度设置为match_parent,同样的道理,如果排列方式为vertical,内部控件绝不能将高度设置为match_parent,当不指定orietation属性时,则默认为水平方向排列

重要属性:通过android:layout_gravity来设置控件与上级视图(即布局)的对齐方式,当这三个控件仍然会坚持以布局所规定的方向排列

<LinearLayout 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="horizontal"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_1"
        android:layout_gravity="top"
        android:text="Button1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_2"
        android:layout_gravity="center_vertical"
        android:text="Button2"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="bottom"
        android:id="@+id/Button_3"
        android:text="Button3"/>

</LinearLayout>

因此运行结果为:

在这里插入图片描述

重要属性android:layout_weight:允许我们使用比例的方式指定控件的大小,即将控件的宽或者高其中一个设置为0dp,则会根据你所设置的数值计算所占的权重,从而规划大小:

<LinearLayout 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="horizontal"
    tools:context=".MainActivity">

    <EditText
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:id="@+id/editText"
        android:hint="Type Something"/>

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/Button_1"
        android:layout_gravity="top"
        android:layout_weight="1"
        android:text="Button1"/>

</LinearLayout>

此时,我们将一个两个控件的宽度都设置为0dp,权重设置为1,此时权重就管的是宽度,它们两个来分配,都占二分之一,运行程序:

在这里插入图片描述

相对布局

  1. 名称:RelativeLayout
  2. 作用:可以通过相对定位的方式让控件出现在布局的任何位置
  3. 对于父布局的定位示例:
<RelativeLayout 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"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_1"
        android:layout_alignParentTop="true"
        android:layout_alignParentStart="true"
        android:text="Button1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_2"
        android:layout_alignParentTop="true"
        android:layout_alignParentEnd="true"
        android:text="Button2"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_3"
        android:layout_centerInParent="true"
        android:text="Button3"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_4"
        android:layout_alignParentBottom="true"
        android:layout_alignParentStart="true"
        android:text="Button4"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_5"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:text="Button5"/>


</RelativeLayout>

运行结果:

在这里插入图片描述

以上是对于父布局进行定位,控件还可以以控件进行定位:

<RelativeLayout 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"
    tools:context=".MainActivity">

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_1"
        android:layout_above="@id/Button_3"
        android:layout_toStartOf="@id/Button_3"
        android:text="Button1"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_2"
        android:layout_above="@id/Button_3"
        android:layout_toEndOf="@id/Button_3"
        android:text="Button2"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_3"
        android:layout_centerInParent="true"
        android:text="Button3"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_4"
        android:layout_below="@id/Button_3"
        android:layout_toStartOf="@id/Button_3"
        android:text="Button4"/>

    <Button
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/Button_5"
        android:layout_below="@id/Button_3"
        android:layout_toEndOf="@id/Button_3"
        android:text="Button5"/>

android:layout_above:可以让一个控件位于另一个控件的上方

android:layout_below:可以让一个控件位于另一个控件的下方

android:layout_toStartOf:可以让一个控件位于另一个控件的左侧

android:layout_toEndOf:可以让一个控件位于另一个控件的右侧

android:layout_alignBottom:一个控件和另一个控件的下边缘对齐
android:layout_alignTop:一个控件和另一个控件的上边缘对齐
android:layout_alignEnd:一个控件和另一个控件的右边缘对齐
android:layout_alignStart:一个控件和另一个控件的左边缘对齐

上面代码运行结果:

在这里插入图片描述

帧布局

  1. 名称:FrameLayout

  2. 作用:没有方便的定位方式,所有的控件都会默认放在布局的左上角,控件堆叠在一起,通常用于覆盖或弹出窗口。

  3. 示例:

<FrameLayout 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"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="This is TextView"/>

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@mipmap/ic_launcher"/>
    
</FrameLayout>

由于都位于左上角,因此文本会被图片遮盖一部分,因此运行结果为:

在这里插入图片描述

除了默认的效果还可以通过android:layout_gravity来指定控件在布局里的对齐方式

网格布局

  1. 名称:GridLayout

  2. 支持多行多列的表格排列

  3. 网格布局默认从左向右、从上到下排列,它新增了两个属性:

    • columnCount属性,它指定了网格的列数,即每行能放多少个视图
    • rowCount属性:它指定了网格的行数,即每列能放多少个视图
  4. 示例:

<GridLayout 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:columnCount="2"
    android:rowCount="2"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="#ffcccc"
        android:gravity="center"
        android:layout_columnWeight="1"
        android:text="aa"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="#00ffff"
        android:gravity="center"
        android:layout_columnWeight="1"
        android:text="aa"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="#ff00cc"
        android:gravity="center"
        android:layout_columnWeight="1"
        android:text="aa"/>

    <TextView
        android:layout_width="0dp"
        android:layout_height="60dp"
        android:background="#ffcc00"
        android:gravity="center"
        android:layout_columnWeight="1"
        android:text="aa"/>


</GridLayout>

定义了一个2行2列的网格布局,并注意其中对于宽度进行了权重的赋值,有代码在网格布局当中权重的设置方式是与前面不一样的,运行界面:

在这里插入图片描述

约束布局

ConstraintLayout:是一种灵活的布局管理器,它允许开发者在Android应用中创建复杂的布局,同时保持性能和灵活性。

相对定位

属性作用
layout_constraintTop_toTopOf将控件的顶部与另一个控件的顶部对齐。
layout_constraintTop_toBottomOf将控件的顶部与另一个控件的底部对齐。
layout_constraintBottom_toBottomOf将控件的底部与另一个控件的底部对齐。
layout_constraintBottom_toTopOf将控件的底部与另一个控件的顶部对齐。
layout_constraintLeft_toLeftOf将控件的左边与另一个控件的左边对齐。
layout_constraintLeft_toRightOf将控件的左边与另一个控件的右边对齐。
layout_constraintRight_toRightOf将控件的右边与另一个控件的右边对齐。
layout_constraintRight_toLeftOf将控件的右边与另一个控件的左边对齐。
layout_constraintStart_toStartOf将控件的开始边与另一个控件的开始边对齐。
layout_constraintStart_toEndOf将控件的开始边与另一个控件的结束边对齐。
layout_constraintEnd_toEndOf:将控件的结束边与另一个控件的结束边对齐。
layout_constraintEnd_toStartOf将控件的结束边与另一个控件的开始边对齐。
layout_constraintBaseline_toBaselineOf将一个控件的基线(baseline)与另一个控件的基线对齐

注意:当出现顶部与底部之间的对齐时这意味着当你将这个属性应用到一个视图上时,它会将视图的顶部放置在另一个所要对其的底部,从而在垂直方向上将它们连接起来。

示例:

<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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <Button
        android:id="@+id/button1"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#ff2200"
        android:text="button1"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="@+id/button2" />

    <Button
        android:id="@+id/buttoncenter"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="@color/teal_200"
        android:text="button center"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toTopOf="parent" />

    <Button
        android:id="@+id/button2"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:layout_marginRight="4dp"
        android:background="#ff4400"
        android:text="button2"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/button1" />

    <Button
        android:id="@+id/button3"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#ff8825"
        android:text="button3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toRightOf="@+id/button1" />

    <Button
        android:id="@+id/button4"
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:background="#ff6677"
        android:text="button4"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toLeftOf="@id/button2" />

</androidx.constraintlayout.widget.ConstraintLayout>

运行结果:

在这里插入图片描述

角度定位

属性作用
layout_constraintCircle指定控件相对于另一个控件的圆形路径进行定位。
layout_constraintCircleAngle指定控件在圆形路径上的角度位置。
layout_constraintCircleRadius指定控件相对于圆形路径的半径。

示例:

<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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/TextView1"
        android:background="#00ff00"
        android:text="TextView1"
        android:visibility="visible"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/TextView2"
        android:background="#ff0033"
        android:text="TextView2"
        android:visibility="visible"
        app:layout_constraintCircle="@id/TextView1"
        app:layout_constraintCircleAngle="120"
        app:layout_constraintCircleRadius="150dp"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_goneMarginLeft="50dp"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

运行结果:

在这里插入图片描述

边距示例:

属性作用
android:layout_marginStart设置控件在其起始边(左边或右边,取决于布局方向)的外边距。
android:layout_marginEnd设置控件在其结束边(右边或左边,取决于布局方向)的外边距。
android:layout_marginLeft设置控件在其左边的外边距。
android:layout_marginTop设置控件在其顶部的外边距。
android:layout_marginRight设置控件在其右边的外边距。
android:layout_marginBottom设置控件在其底部的外边距。

当给marginBottom前面加上gone时就代表控件在不可用时相对应位置的外边距

示例:

<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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/TextView1"
        android:background="#00ff00"
        android:text="TextView1"
        android:visibility="visible"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintTop_toTopOf="parent"/>

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/TextView2"
        android:background="#ff0033"
        android:text="TextView2"
        android:visibility="visible"
        app:layout_constraintLeft_toRightOf="@id/TextView1"
        app:layout_goneMarginLeft="50dp"
        app:layout_constraintTop_toTopOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

运行结果:

在这里插入图片描述

当我们将第一个控件的可见性属性进行改变:android:visibility="gone",由于设置,此时运行结果为:

在这里插入图片描述

居中和偏移:

居中:

<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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="100dp"
        android:layout_height="100dp"
        android:id="@+id/TextView1"
        android:background="#00ff00"
        android:text="TextView1"
        android:visibility="visible"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintRight_toRightOf="parent"/>

</androidx.constraintlayout.widget.ConstraintLayout>

运行之后,此时就会有一个TextView位于屏幕的中间:

在这里插入图片描述

偏移:

属性作用
layout_constraintHorizontal_bias水平偏移
layout_constraintVertical_bias垂直偏移

偏移量的设置范围为0~1,当设置偏移量为1时,当为水平偏移时就会位于最右端,当为垂直偏移时,就会位于最下端。当为0.5就会位于中间,以此类推。

尺寸约束

  1. 当我们使用wrap_content,即让控件自己确定大小,此时我们可以设立属性来规定它的最大最小宽度与高度:

    android:minWidth 最小的宽度
    android:minHeight 最小的高度
    android:maxWidth 最大的宽度
    android:maxHeight 最大的高度
    
  2. 使用0dp:

    match_parent 是一个布局参数,它可以使视图的尺寸与父容器的尺寸相匹配。然而,ConstraintLayout 推荐使用 MATCH_CONSTRAINT (在XML中表示为 0dp)来代替 match_parent,因为它提供了更多的灵活性和控制。

    使用 MATCH_CONSTRAINT 时,可以通过设置视图的约束来控制其尺寸。例如,你可以让视图的宽度或高度匹配父容器,或者根据其他视图的尺寸来调整自己的尺寸。这样做的好处是,它允许视图在不同屏幕尺寸和方向下保持更好的适应性。

示例:

 <TextView
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:id="@+id/TextView1"
        android:background="#00ff00"
        android:text="TextView1"
        android:visibility="visible"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

在一般情况下,当我们设置了android:layout_width="0dp"时,这个视图就看不到了,但在约束布局当中由于我们设立了左右要与父视图对齐,因此运行结果如下:

在这里插入图片描述

  1. 宽高比:当宽或高至少有一个尺寸被设置为0dp时,可以通过属性layout_constraintDimensionRatio设置宽高比

示例:

<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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:id="@+id/TextView1"
        android:background="#00ff00"
        android:text="TextView2"
        android:visibility="visible"
        app:layout_constraintDimensionRatio="1:1"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:id="@+id/TextView2"
        android:background="#00ff00"
        android:text="TextView2"
        android:visibility="visible"
        app:layout_constraintDimensionRatio="H,2:3"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintRight_toRightOf="parent" />

    <TextView
        android:layout_width="0dp"
        android:layout_height="100dp"
        android:id="@+id/TextView3"
        android:background="#00ff00"
        android:text="TextView1"
        android:visibility="visible"
        app:layout_constraintDimensionRatio="W,2:3"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintLeft_toLeftOf="parent" />

</androidx.constraintlayout.widget.ConstraintLayout>

运行结果:

在这里插入图片描述

一般没有特殊声明时,指的为高比宽,也可在前面加上比例的限制,例如上面的示例文本控件2与文本控件3就加了限制,当前面为H时代表的是高比宽,当前面为W时,代表的是宽比高。

在约束布局中,链(Chains)是一种用于定义一组相关控件之间关系的方法,可以控制它们的排列方式和行为。

属性作用
app:layout_constraintHorizontal_chainStyle定义水平链的样式,可以设置为 spread(均匀分布)、spread_inside(均匀分布,但不包括边缘控件)或 packed(靠拢排列)。
app:layout_constraintVertical_chainStyle定义垂直链的样式,可以设置为 spread、spread_inside或 packed。
app:layout_constraintHorizontal_bias设置水平链中每个控件的偏移量,取值范围为 0.0(左边)到 1.0(右边)。
app:layout_constraintVertical_bias设置垂直链中每个控件的偏移量
app:layout_constraintHorizontal_weight定义水平链中每个控件的权重,用于均匀分配额外空间。
app:layout_constraintVertical_weight定义垂直链中每个控件的权重。

示例:

<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:id="@+id/main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:id="@+id/TextView1"
        android:background="#00ff00"
        android:text="TextView2"
        android:visibility="visible"
        app:layout_constraintHorizontal_chainStyle="spread_inside"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toLeftOf="parent"
        app:layout_constraintRight_toLeftOf="@id/TextView2" />

    <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:id="@+id/TextView2"
        android:background="#ff0011"
        android:text="TextView2"
        android:visibility="visible"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintLeft_toRightOf="@id/TextView1"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintRight_toLeftOf="@id/TextView3" />

    <TextView
        android:layout_width="50dp"
        android:layout_height="wrap_content"
        android:id="@+id/TextView3"
        android:background="#1100ff"
        android:text="TextView1"
        android:visibility="visible"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintRight_toRightOf="parent"
        app:layout_constraintLeft_toRightOf="@id/TextView2" />

</androidx.constraintlayout.widget.ConstraintLayout>

运行程序,此时结果为:

在这里插入图片描述

当我们将第一个的属性改变:app:layout_constraintHorizontal_chainStyle="spread"

在这里插入图片描述
app:layout_constraintHorizontal_chainStyle="packed",此时三个TextView为挨在一起的

到这里就结束了!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1938453.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

基于Semaphore与CountDownLatch分析AQS共享模式实现

共享模式与独占模式区别在于&#xff1a;共享模式下允许多条线程同时获取锁资源&#xff0c;而在之前分析的独占模式中&#xff0c;在同一时刻只允许一条线程持有锁资源。 一、快速认识Semaphore信号量及实战 Semaphore信号量是java.util.concurrent(JUC)包下的一个并发工具类…

2-40 基于Matlab编写的3维FDTD(时域有限差分算法)计算了球的RCS经典散射问题

基于Matlab编写的3维FDTD(时域有限差分算法)计算了球的RCS经典散射问题&#xff0c;采用PEC作边界&#xff0c;高斯波束激励。程序已调通&#xff0c;可直接运行。 2-40 3维FDTD 时域有限差分算法 - 小红书 (xiaohongshu.com)

机器学习——降维算法PCA和SVD(sklearn)

目录 一、基础认识 1. 介绍 2. 认识 “ 维度 ” &#xff08;1&#xff09;数组和Series &#xff08;2&#xff09;DataFrame 表 &#xff08;3&#xff09;图像 3. 降维思想 4. 降维步骤 二、降维算法&#xff08;PCA&#xff09; 1. PCA实现 &#xff08;1&#…

免费视频批量横版转竖版

简介 视频处理器 v1.3 是一款由是貔貅呀开发的视频编辑和处理工具&#xff0c;提供高效便捷的视频批量横转竖&#xff0c;主要功能&#xff1a; 导入与删除文件&#xff1a;轻松导入多个视频文件&#xff0c;删除不必要的文件。暂停与继续处理&#xff1a;随时暂停和继续处理。…

7-20FPGA调试日志

1. 在代码里面定义的ILA的变量名称与波形抓取界面的不一致 问题描述 ::: 2. 直接从其他的播放声音的平台放音乐没问题&#xff0c;但是从AU里面生成的2kHz的正弦波放不出声音 演示视频链接 好像和ILA的例化信号有关&#xff0c;例化ILA信号的驱动时钟信号频率没有内部的其他…

Redis-应用

目录 应用 缓存雪崩、击穿、穿透和解决办法? 布隆过滤器是怎么工作的? 缓存的数据一致性怎么保证 Redis和Mysql消息一致性 业务一致性要求高怎么办? 数据库与缓存的一致性问题 数据库和缓存的一致性如何保证 如何保证本地缓存和分布式缓存的一致&#xff1f; 如果在…

电脑永久性不小心删除了东西还可以恢复吗 电脑提示永久性删除文件怎么找回 怎么恢复电脑永久删除的数据

永久删除电脑数据的操作&#xff0c;对于很多常用电脑设备的用户来说&#xff0c;可以说时有发生&#xff01;但是&#xff0c;因为这些情况大都发生在不经意间&#xff0c;所以每每让广大用户感觉到十分苦恼。永久删除也有后悔药&#xff0c;轻松找回电脑中误删的文件。恢复文…

Github 2024-07-20 Rust开源项目日报 Top10

根据Github Trendings的统计,今日(2024-07-20统计)共有10个项目上榜。根据开发语言中项目的数量,汇总情况如下: 开发语言项目数量Rust项目10TypeScript项目1Rust: 构建可靠高效软件的开源项目 创建周期:5064 天开发语言:Rust协议类型:OtherStar数量:92978 个Fork数量:1…

Win10环境将Docker部署到非系统盘

Win10环境将Docker部署到非系统盘 目录 Win10环境将Docker部署到非系统盘 一、Docker官网客户端Docker Hub下载 二、windows环境的安装 三、正确的迁移步骤 3.1、确保你的系统分区至少3G的剩余空间&#xff1b; 3.2、默认方式安装Docker hub&#xff1b; 3.3、打开Dock…

linux操作系统之线程

1.线程概念 线程是一个轻量级进程,每一个线程都属于一个进程 进程是操作系统资源分配的最小单位,而线程是CPU任务调度的最小单位 线程是一个任务执行的过程,包括创建,调度,消亡 创建:线程空间位于进程空间,进程中的线程,栈区独立,并共享进程中的数据区,文本区,堆区 调度:宏观…

微积分-微分应用2(平均值定理)

要得出平均值定理&#xff0c;我们首先需要以下结果。 罗尔定理 设函数 f f f 满足以下三个假设&#xff1a; f f f 在闭区间 [ a , b ] [a, b] [a,b] 上连续。 f f f 在开区间 ( a , b ) (a, b) (a,b) 上可导。 f ( a ) f ( b ) f(a) f(b) f(a)f(b) 则在开区间 ( a , b …

【手撕数据结构】拿捏双向链表

目录 链表介绍初始化链表销毁链表查找节点打印链表增加节点尾插头插在指定位置之后插入节点 删除节点尾删头删删除指定位置节点 链表判空 链表介绍 前面说到&#xff0c;链表的结构一共有八种&#xff1a;带头单向循环链表、带头单向非循环链表、带头双向循环链表、带头双向非…

绿色算力|暴雨服务器用芯片筑起“十四五”转型新篇章

面对全球气候变化、技术革新以及能源转型的新形势&#xff0c;发展低碳、高效的绿色算力不仅是顺应时代的要求&#xff0c;更是我国建设数字基础设施和展现节能减碳大国担当的重要命题&#xff0c;在此背景下也要求在提升算力规模和性能的同时&#xff0c;积极探索推动算力基础…

计算机网络参考模型与5G协议

目录 OSI七层参考模型OSI模型vsTCP/IP模型TCP/IP协议族的组成 OSI七层参考模型 分层功能应用层网络服务与最终用户的一个接口表示层数据的表示,安全,压缩会话层建立,管理,终止会话传输层定义传输数据的协议端口号,以及流控和差错校验网络层进行逻辑地址寻址,实现不同网路之间的…

泛型新理解

1.创建三个类&#xff0c;并写好对应关系 package com.jmj.gulimall.study;public class People { }package com.jmj.gulimall.study;public class Student extends People{ }package com.jmj.gulimall.study;public class Teacher extends People{ }2.解释一下这三个方法 pub…

麻省理工学院 - MIT - 线性代数学习笔记

学习视频地址 文章目录 1.01方程组的几何解释2.02矩阵消元3.03乘法和逆矩阵乘法逆 4.04矩阵A的LU分解5.05转置&#xff0c;置换&#xff0c;向量空间置换转置向量空间 6.06列空间和零空间7.07求解Ax0&#xff1a;主变量&#xff0c;特解 1.01方程组的几何解释 对于二元方程组&…

重生之我们在ES顶端相遇第6 章- Dynamic Mapping(动态映射)

思维导图 前言 在第5章&#xff0c;我们说完 ES 常用字段类型。但是&#xff0c;并未跟大家解释&#xff0c;为什么不设置 Mapping&#xff0c;写入的字符串&#xff0c;默认就可以全文搜索。例如 PUT /test4/_doc/1 {"name": "hello world" } GET /test…

Qt开发网络嗅探器01

引言 随着互联网的快速发展和普及&#xff0c;人们对网络性能、安全和管理的需求日益增 长。在复杂的网络环境中&#xff0c;了解和监控网络中的数据流量、安全事件和性能 问题变得至关重要。为了满足这些需求&#xff0c;网络嗅探器作为一种重要的工具被 广泛应用。 网络嗅探…

IoTDB 分段查询语句详解:GROUP BY + 时序语义

GROUP BY 查询子句的时序语义展开&#xff0c;IoTDB 支持的分段方式总结&#xff01; 存储的数据通过分析来发挥价值&#xff0c;当一组被存储的数据通过查询得到分析后的结果时&#xff0c;这些数据才真正在数据库中实现了价值闭环。 在关系型数据库中&#xff0c;GROUP BY 子…

微信小程序数组绑定使用案例(二)

一、数组事件绑定&#xff0c;事件传递数据 1.wxml <text>姓名&#xff1a;{{name}} </text> <block wx:for"{{list}}"><button bind:tap"nameClick2" data-name"{{item}}">修改:{{item}}</button> </block&…