0

我在 Adob​​e XD 中设计了一个如图所示的启动画面: 在此处输入图像描述

现在,当我将图像的部分导出到 android studio 时,我无法像 XD 中那样让所有图像都粘在底部。在此处输入图像描述

有人能告诉我我将如何去做,并且将成为此类任务的最佳 ViewGroup 吗?

这是我的 XML 文件:

<?xml version="1.0" encoding="utf-8"?>
<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/linearLayout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@drawable/gradient"
    tools:context=".MainActivity">


    <ImageView
        android:id="@+id/imageView"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="centerCrop"
        android:src="@drawable/group_1"
        app:layout_constraintBottom_toBottomOf="parent"
        app:layout_constraintStart_toStartOf="parent"
        app:layout_constraintTop_toTopOf="parent"
        app:layout_constraintVertical_bias="1.0" />

</LinearLayout>
4

1 回答 1

0

它可以用任何一个来完成ViewGroup。但问题不在于视图组 - 问题在于整个内容只有一个图像 - 这是不好的做法。

应该至少有 2 张图像 - 一张用于背景,另一张用于内容。

这是由于有关设备屏幕的碎片问题 - 有太多不同的分辨率、纵横比和 dpi 以使单个图像在它们上都能正常工作。

我将向您展示一个基于您的 UI 的示例,该示例带有背景和徽标图像,徽标下方带有小图像。您只需要将其分成两个文件 - 背景可以是 jpg,但徽标必须是具有透明度的 png。万一你会这样做 - 这是你的布局应该是什么样子。

<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="@color/white"
    android:orientation="vertical">

    <ImageView
        android:id="@+id/background"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:scaleType="fitXY"
        android:src="@drawable/bg" />

    <ImageView
        android:id="@+id/content"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_gravity="center"
        android:adjustViewBounds="true"
        android:padding="24dp"
        android:src="@drawable/logo" />

</FrameLayout>

您可能想尝试android:paddingandroid:scaleType获得最佳结果。

编辑

更改android:layout_height="match_parent"android:layout_height="wrap_content"- 这样会更好

希望能帮助到你。

于 2019-10-05T19:36:26.390 回答