Android 入职屏幕的哪个布局

Android 入职屏幕的哪个布局,android,android-layout,Android,Android Layout,对于我的应用程序,我创建了一个入职屏幕的模型,如下所示: 现在我不完全清楚如何在Android布局中设计它。下面的课文不应该这么难。最大的问题是顶部有灰色区域。所有灰色部分都应该是ImageViews,比例为1:1,这样我就可以分别为它们设置动画 您认为我应该使用哪种布局(RelativeLayout,ConstraintLayout,等等)?我认为最好避免硬编码的dp值,这样它看起来与屏幕大小和分辨率无关。所以这里的百分比值更好,对吗 强>编辑< /强>:这是我当前的布局,但是我不能得到中间

对于我的应用程序,我创建了一个入职屏幕的模型,如下所示:

现在我不完全清楚如何在Android布局中设计它。下面的课文不应该这么难。最大的问题是顶部有灰色区域。所有灰色部分都应该是
ImageView
s,比例为
1:1
,这样我就可以分别为它们设置动画

您认为我应该使用哪种布局(
RelativeLayout
ConstraintLayout
,等等)?我认为最好避免硬编码的dp值,这样它看起来与屏幕大小和分辨率无关。所以这里的百分比值更好,对吗

<>强>编辑< /强>:这是我当前的布局,但是我不能得到中间的4个圆圈……

<android.support.constraint.ConstraintLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/colorPrimary"
    android:padding="16dp">

    <ImageView
        android:id="@+id/icon"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:adjustViewBounds="true"
        android:contentDescription="@string/empty"
        android:cropToPadding="true"
        android:padding="48dp"
        android:tint="@color/colorPrimaryDark"
        app:layout_constraintDimensionRatio="w,1:1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintHorizontal_bias="0.3"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:srcCompat="@drawable/ringer" />

    <ImageView
        android:id="@+id/location"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/empty"
        app:layout_constraintDimensionRatio="w,1:1"
        app:layout_constraintEnd_toStartOf="@+id/timerange"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@id/icon"
        app:srcCompat="@drawable/location" />

    <ImageView
        android:id="@+id/timerange"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/empty"
        app:layout_constraintDimensionRatio="w,1:1"
        app:layout_constraintEnd_toStartOf="@+id/wifi"
        app:layout_constraintStart_toEndOf="@+id/location"
        app:layout_constraintTop_toBottomOf="@id/icon"
        app:srcCompat="@drawable/sound_alarm" />

    <ImageView
        android:id="@+id/wifi"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/empty"
        app:layout_constraintDimensionRatio="w,1:1"
        app:layout_constraintEnd_toStartOf="@+id/bluetooth"
        app:layout_constraintStart_toEndOf="@+id/timerange"
        app:layout_constraintTop_toBottomOf="@id/icon"
        app:srcCompat="@drawable/wifi" />

    <ImageView
        android:id="@+id/bluetooth"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:contentDescription="@string/empty"
        app:layout_constraintDimensionRatio="w,1:1"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toEndOf="@+id/wifi"
        app:layout_constraintTop_toBottomOf="@id/icon"
        app:srcCompat="@drawable/bluetooth" />

    <TextView
        android:id="@+id/title"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:paddingBottom="24dp"
        android:text="@string/onboardTitle1"
        android:textAlignment="center"
        android:textColor="@android:color/white"
        android:textSize="24sp"
        app:layout_constraintEnd_toEndOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/timerange" />

    <TextView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:padding="8dp"
        android:text="@string/onboardDescrption1"
        android:textAlignment="center"
        android:textColor="@android:color/white"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toBottomOf="@+id/title" />

</android.support.constraint.ConstraintLayout>

我会从一个
RelativeLayout
开始,然后在里面嵌套一个固定高度的
线性布局

我的理由如下:

  • 您的四个较小的圆都在单独的列中(不要重叠),这使得线性布局可以轻松地将它们隔开
  • 父相对布局将允许您将线性布局向上移动页面(因此其不可见部分与较大的图像重叠)
  • LinearLayout的固定高度允许您简单地使用重力将圆放置在顶部和底部边界,以创建所显示的布局

    <RelativeLayout>
        <ImageView android:id="@+id/square" />
        <LinearLayout android:layout_height="100dp"
                      android:layout_marginTop="-24dp">
             <ImageView android:foregroundGravity="top" />
             <ImageView android:foregroundGravity="bottom" />
             <ImageView android:foregroundGravity="bottom" />
             <ImageView android:foregroundGravity="top" />
        </LinearLayout>
    </RelativeLayout>
    
    
    

根据您的矩阵,使用前景重力可能不适合您。如果是这种情况,请忘记线性布局的固定高度,然后为“底部”对齐的图像添加上边距

您可以尝试以下操作

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/infoBlue"
    android:orientation="vertical"
    android:padding="16dp">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:gravity="bottom">
        <ImageView
            android:id="@+id/icon"
            android:layout_width="130dp"
            android:layout_height="wrap_content"
            android:layout_centerInParent="true"
            android:background="@color/gray"
            android:contentDescription="@string/empty"
            android:cropToPadding="true"
            android:padding="48dp"
            android:tint="@color/colorPrimaryDark" />

        <ImageView
            android:id="@+id/location"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_below="@+id/icon"
            android:layout_marginRight="10dp"
            android:layout_toLeftOf="@+id/icon"
            android:layout_toStartOf="@+id/icon"
            android:background="@color/gray"
            android:contentDescription="@string/empty" />

        <ImageView
            android:id="@+id/timerange"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_below="@+id/icon"
            android:layout_marginLeft="10dp"
            android:layout_toEndOf="@+id/icon"
            android:layout_toRightOf="@+id/icon"
            android:background="@color/gray"
            android:contentDescription="@string/empty" />
    </RelativeLayout>

    <LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_gravity="center_horizontal"
        android:orientation="horizontal">

        <ImageView
            android:id="@+id/wifi"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_below="@+id/icon"
            android:layout_marginEnd="40dp"
            android:layout_marginRight="40dp"
            android:layout_toEndOf="@+id/icon"
            android:layout_toRightOf="@+id/icon"
            android:background="@color/gray"
            android:contentDescription="@string/empty" />

        <ImageView
            android:id="@+id/bluetooth"
            android:layout_width="40dp"
            android:layout_height="40dp"
            android:layout_below="@+id/icon"
            android:layout_marginLeft="10dp"
            android:layout_toEndOf="@+id/icon"
            android:layout_toRightOf="@+id/icon"
            android:background="@color/gray"
            android:contentDescription="@string/empty" />
    </LinearLayout>
</LinearLayout>

在我的案例中,它看起来如下所示


不知道如何回答,但看起来很漂亮
你认为我应该使用哪种布局?
回答-。你能看看我当前的布局吗?这是投票答案还是什么?me投票选择线性和权重的相对布局组合;)参考