导航抽屉滞后于ImageView

noo*_*oot 6 android android-layout

每当我向我的活动添加ImageView时,我的应用程序中的导航抽屉都会滞后.没有图像,它运行顺畅.我猜测滞后是因为我们打开导航抽屉时活动不断刷新.图像分辨率约为1200x800.我尝试使用较低的res图像,但滞后仍然存在.我正在使用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>
Run Code Online (Sandbox Code Playgroud)

这是抽屉布局xml代码:

<?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>
Run Code Online (Sandbox Code Playgroud)

这是抽屉布局的java代码

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();
Run Code Online (Sandbox Code Playgroud)

有没有办法避免这种滞后?

Mr *_*bot 4

通过TinyPNG.com压缩您的绘图

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