Android 导航抽屉滞后于ImageView

Android 导航抽屉滞后于ImageView,android,android-layout,Android,Android Layout,每当我在活动中添加ImageView时,我应用程序中的导航抽屉就会滞后很多。它运行平稳,没有图像。我猜延迟是因为我们打开导航抽屉时,活动不断刷新。图像分辨率约为1200x800。我尝试使用较低分辨率的图像,但延迟仍然存在。我正在使用Android Studio 1.4中默认的导航抽屉活动 这是我的xml代码: <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:app="h

每当我在活动中添加ImageView时,我应用程序中的导航抽屉就会滞后很多。它运行平稳,没有图像。我猜延迟是因为我们打开导航抽屉时,活动不断刷新。图像分辨率约为1200x800。我尝试使用较低分辨率的图像,但延迟仍然存在。我正在使用Android Studio 1.4中默认的导航抽屉活动

这是我的xml代码:

<RelativeLayout 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:layout_width="match_parent"
    android:layout_height="match_parent"
    app:layout_behavior="@string/appbar_scrolling_view_behavior"
    tools:context=".HomeScreen"
    tools:showIn="@layout/app_bar_home_screen">



    <TextView
        android:id="@+id/textView"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentStart="true"
        android:layout_alignParentTop="true"
        android:layout_margin="16dp"
        android:text="Replace with home screen"
        android:textAppearance="?android:attr/textAppearanceLarge"
        android:textColor="#000" />

    <ImageView
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:id="@+id/imageView"
        andoird:scaleType="centerCrop"
        android:layout_alignTop="@+id/textView"
        android:layout_alignParentStart="true"
        android:layout_alignParentBottom="true"
        android:layout_alignParentEnd="true"
        android:src="@drawable/dinner" />
</RelativeLayout>
<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.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:fitsSystemWindows="true"
    tools:openDrawer="start">

    <include
        layout="@layout/app_bar_home_screen"
        android:layout_width="match_parent"
        android:layout_height="match_parent" />

    <android.support.design.widget.NavigationView
        android:id="@+id/nav_view"
        android:layout_width="wrap_content"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:fitsSystemWindows="true"
        app:headerLayout="@layout/nav_header_home_screen"
        app:menu="@menu/home_screen_drawer" />

</android.support.v4.widget.DrawerLayout>

有没有办法避免这种延迟?

通过


TinyPNG使用智能有损压缩技术来减小PNG文件的文件大小。通过有选择地减少图像中的颜色数量,存储数据所需的字节更少。这种效果几乎是看不见的,但它在文件大小上有很大的不同

问题在于imageview占用了大量内存。 解决办法就是这样! 使新文件夹可绘制nodpi。 将所有资源放入该文件夹。
希望这些帮助:)

让我们把事情简单化

将图像从转换为SVG格式

然后转到androidstudio,用这个SVG格式创建一个向量资产


然后在XML中更改您喜欢的颜色以供背景使用。

我尝试缩小图像的大小(从),效果很好。您能告诉我您将图像缩小到了什么大小吗?而且,如果它太小,这不是一个标签的问题吗?约400像素。。。此外,还有一个保持相同质量的图像选择。。。选中该选项后,不会有任何问题有一件事我忘了提到,我用这张图片作为背景,所以400px看起来不坏吗?我认为你的答案是好的,但不完整。我有一些滞后,即使压缩我的图像。但伟大的网站,谢谢!好的,我的图像太大了(像1800x1200),现在它像地狱一样平滑了=谢谢
DrawerLayout drawer = (DrawerLayout) findViewById(R.id.drawer_layout);
        ActionBarDrawerToggle toggle = new ActionBarDrawerToggle(
                this, drawer, toolbar, R.string.navigation_drawer_open, R.string.navigation_drawer_close);
        drawer.setDrawerListener(toggle);
        toggle.syncState();