android - Android Studio 中 xml 上的图像在高度方向上异常拉伸(stretch)

标签 android json

编辑:我的图像存在分辨率问题,分辨率越高,空白区域越多。但我无法获得正确的分辨率。如果分辨率太高,问题就在这里,如果它足以让图像适合 720p 显示器,那么 QHD 或更高显示器上的图像质量就会很差。除了分辨率之外,我似乎无法在互联网上找到任何其他解决方案,所以请帮忙!

我放在 XML 上的图像没有可见的 layout_marginVertical。我没有把那个属性放在那里,如果我写的话,它确实会垂直放置那个边距,从而导致困惑的情况。即使我包装了所有内容,也会发生这种情况。这是我在代码中插入的图像:

Image

这是我得到的结果:

![result

这是我的代码:

<?xml version="1.0" encoding="utf-8"?>
<androidx.drawerlayout.widget.DrawerLayout 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/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:background="?attr/backgroundcolor"
    tools:context=".RegistrationActivity">

    <RelativeLayout
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:orientation="vertical">

        <androidx.appcompat.widget.Toolbar
            android:id="@+id/toolbar"
            android:layout_width="match_parent"
            android:layout_height="?attr/actionBarSize"
            android:background="@color/colorPrimary"
            android:elevation="4dp"
            android:theme="@style/ThemeOverlay.AppCompat.Dark.ActionBar"
            app:popupTheme="@style/ThemeOverlay.AppCompat.Light" />

        <ScrollView
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:layout_below="@+id/toolbar">

            <LinearLayout
                android:layout_width="match_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical"
                android:padding="10dp">

                <androidx.cardview.widget.CardView
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content">

                    <ImageView
                        android:layout_width="wrap_content"
                        android:layout_height="wrap_content"
                        android:src="@drawable/android_course_thumbnail"
                        android:layout_marginBottom="20sp"/>

                </androidx.cardview.widget.CardView>

            </LinearLayout>

        </ScrollView>

    </RelativeLayout>

    <com.google.android.material.navigation.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:background="?attr/backgroundcolor"
        app:headerLayout="@layout/navigation_header"
        app:menu="@menu/navigation_menu" />

</androidx.drawerlayout.widget.DrawerLayout>

最佳答案

删除 ScrollView ,并将图像调整为 480x800 分辨率

关于android - Android Studio 中 xml 上的图像在高度方向上异常拉伸(stretch),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53260696/

相关文章:

android - GCM Error=MissingRegistration 通过 JSON 发送消息

r - 如何解决此 RCurl 错误 : "SSL certificate problem: certificate has expired"?

java - 如何从字符串中提取图像url?

ios - 将数组内容正确存储到带有键的字典中

android - Jacoco 报告不排除指定文件

Android - 在 SurfaceTexture 上绘制 YouTube 视频

json - 大纪元时间(自 1970 年开始计时)- Mac 与 Windows

java - 如何将 jsonNodes 列表转换为单个 jsonNode

java - 无法仅在控制台中启动androidstudio

java - 如何用 ToMany 关系注释由 greendao 创建的字段