gpt4 book ai didi

android - 抽屉导航滞后于 ImageView

转载 作者:塔克拉玛干 更新时间:2023-11-02 20:49:49 25 4
gpt4 key购买 nike

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

这是我的 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 代码:

<?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>

这是抽屉布局的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();

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

最佳答案

通过 TinyPNG.com 压缩您的可绘制对象

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

关于android - 抽屉导航滞后于 ImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33704547/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com