【问题标题】:Need to make my Splash screen fits all the devices?需要让我的启动画面适合所有设备吗?
【发布时间】:2021-03-06 17:20:13
【问题描述】:

我需要让我的启动画面适合所有设备。它在 nexus 上运行完美,但在其他设备上动画有点不同。这是我的闪屏活动。我认为问题在于 Y 轴和 X 轴在其他设备上的工作方式不同

    logo = findViewById(R.id.logo);
    splashImg = findViewById(R.id.img);
    lottieAnimationView = findViewById(R.id.lottie);

    splashImg.animate().translationY(-2000).setDuration(1000).setStartDelay(4000);
    logo.animate().translationY(1100).setDuration(1000).setStartDelay(4000);
    lottieAnimationView.animate().translationY(1400).setDuration(1000).setStartDelay(4000);

在初始 XML 中

    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        app:layout_behavior="@string/appbar_scrolling_view_behavior"
        tools:layout_conversion_absoluteHeight="731dp"
        tools:layout_conversion_absoluteWidth="411dp"
        tools:layout_editor_absoluteX="0dp"
        tools:layout_editor_absoluteY="0dp" >
       <androidx.constraintlayout.widget.ConstraintLayout
           android:layout_width="match_parent"
           android:layout_height="match_parent"
           >
           <ImageView
               android:id="@+id/img"
               android:layout_width="wrap_content"
               android:layout_height="900dp"
               android:src="@drawable/shafaqat"
               app:layout_constraintVertical_bias="0"
               android:scaleType="centerCrop"
               app:layout_constraintBottom_toBottomOf="parent"
               app:layout_constraintEnd_toEndOf="parent"
               app:layout_constraintStart_toStartOf="parent"
               app:layout_constraintTop_toTopOf="parent"

               />

           <ImageView

               android:id="@+id/logo"
               android:layout_width="300dp"
               android:layout_height="300dp"
               android:src="@drawable/logo"
               app:layout_constraintVertical_bias=".1"
               app:layout_constraintBottom_toBottomOf="parent"
               app:layout_constraintEnd_toEndOf="parent"
               app:layout_constraintStart_toStartOf="parent"
               app:layout_constraintTop_toTopOf="parent"/>

           <com.airbnb.lottie.LottieAnimationView
               android:id="@+id/lottie"
               app:lottie_autoPlay="true"
               android:layout_width="wrap_content"
               android:layout_height="200dp"
               app:layout_constraintVertical_bias="0"
               app:lottie_rawRes="@raw/splash"
               app:layout_constraintEnd_toEndOf="parent"
               app:layout_constraintStart_toStartOf="parent"
               app:layout_constraintTop_toBottomOf="@+id/logo" />
       </androidx.constraintlayout.widget.ConstraintLayout>
    </FrameLayout>

【问题讨论】:

  • 不要硬编码高度/宽度...900dp 太贪心了
  • 我应该赚多少钱?

标签: android


【解决方案1】:

我会使用权重并填充内容视图

如果我想要所有屏幕视图,请在 size 属性中使用填充内容,如果您希望您的徽标位于中心,我使用带有 height 属性的视图来设置间距,如 bootstrap

我会放置三个视图,每个视图具有相同的权重,在中间视图中我会放置具有填充内容大小的图像视图,这是我制作具有相同资源保持比例的响应式视图的方法

这是一个关于如何使用权重的示例

<LinearLayout
    android:layout_width="fill_parent"
    android:layout_height="wrap_content"
    android:weightSum="5">

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="1" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="3"
        android:text="2" />

    <Button
        android:layout_width="0dp"
        android:layout_height="wrap_content"
        android:layout_weight="1"
        android:text="3" />

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2012-08-07
    • 1970-01-01
    • 2021-11-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多