每當我將ImageView添加到我的活動時,我的應用中的導航抽屜滯後很多。它運行平穩,沒有圖像。我猜測滯後是因爲我們打開導航抽屜時活動不斷刷新。圖像分辨率約爲1200x800。我嘗試使用較低分辨率的圖像,但滯後仍然存在。我使用自帶默認Android Studio中的抽屜式導航活動1.4導航抽屜落後於ImageView
這是我的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();
有沒有辦法避免這種滯後?
我試圖減小圖像的大小(從[這裏](http://www.reduceimages.com/)),它對我來說 –
你能告訴你什麼大小減少圖像?而且,如果它太小,它不會是標籤問題嗎? – nootnoot
大約400像素...還有一個選項,保持相同質量的圖像...與該選項檢查不會有任何問題 –