在相对布局中子组件的位置是由相对兄弟组件或者父容器来决定的。出于性能的考虑,在设计相对布局时,要按照组件的依赖关系进行排列。例如:View A的位置要由View B决定,则要保证布局文件中View B要在View A之前。

现在安卓开发默认布局就是相对布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:andro
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.demo.RelativeLayout">
    <ImageView
        android:layout_width="100dp"
        android:layout_height="70dp"
        android:
        android:layout_centerInParent="true"
        android:src="@drawable/test"/>
    <ImageView
        android:layout_width="120dp"
        android:layout_height="80dp"
        android:
        android:src="@drawable/test2"
        android:layout_above="@+id/imageView1"
        android:layout_alignStart="@+id/imageView3" />
    <ImageView
        android:layout_width="120dp"
        android:layout_height="80dp"
        android:
        android:layout_below="@+id/imageView1"
        android:layout_centerHorizontal="true"
        android:src="@drawable/test3"/>
    <ImageView
        android:layout_width="120dp"
        android:layout_height="80dp"
        android:
        android:layout_toLeftOf="@+id/imageView1"
        android:layout_alignTop="@+id/imageView1"
        android:src="@drawable/test4"/>
    <ImageView
        android:layout_width="120dp"
        android:layout_height="80dp"
        android:
        android:layout_toRightOf="@+id/imageView1"
        android:layout_alignTop="@+id/imageView1"
        android:src="@drawable/test5"/>
</RelativeLayout>


Android布局(4)--相对布局(RelativeLayout)

 

相关文章:

  • 2021-11-30
  • 2021-11-30
  • 2021-12-10
  • 2021-12-10
  • 2022-01-11
  • 2021-11-30
  • 2021-12-10
  • 2021-12-10
猜你喜欢
  • 2021-11-30
  • 2021-12-10
  • 2021-12-10
  • 2021-08-13
  • 2022-12-23
  • 2021-11-30
相关资源
相似解决方案