首页 > 解决方案 > 如何在启动画面中心设置徽标?

问题描述

我正在尝试在 dp 中有一个以 layout_width 和 layout_height 为中心的徽标图像启动画面。徽标图像直接从位于 的徽标文件夹中获取@mipmap/ic_launcher

问题: 我无法将徽标图像居中。

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:background="@color/launch_background"
>
  <ImageView 
    android:src="@mipmap/ic_launcher"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_centerInParent="true"
    android:scaleType="centerCrop"
  >
  </ImageView>
</FrameLayout>

标签: android

解决方案


您可以将其添加android:layout_gravity="center"到您ImageView的中心FrameLayout

<?xml version="1.0" encoding="utf-8"?>
<FrameLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="match_parent"
  android:orientation="vertical"
  android:background="@color/launch_background"
>
  <ImageView 
    android:src="@mipmap/ic_launcher"
    android:layout_width="100dp"
    android:layout_height="100dp"
    android:layout_gravity="center"
    android:scaleType="centerCrop"
  >
  </ImageView>
</FrameLayout>

推荐阅读