2015-11-14 34 views
4

每當我將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(); 

有沒有辦法避免這種滯後?

+0

我試圖減小圖像的大小(從[這裏](http://www.reduceimages.com/)),它對我來說 –

+0

你能告訴你什麼大小減少圖像?而且,如果它太小,它不會是標籤問題嗎? – nootnoot

+0

大約400像素...還有一個選項,保持相同質量的圖像...與該選項檢查不會有任何問題 –

回答

4

通過TinyPNG.com

壓縮您的可繪TinyPNG使用智能有損壓縮技術,以減少您的PNG文件的文件大小。通過有選擇地減少圖像中的顏色數量,需要更少的字節來存儲數據。效果幾乎看不見,但是它在文件大小上造成了很大的差異!

+1

我認爲你的答案很好,但不完整。 我有一些滯後,即使壓縮我的圖像。 但很棒的網站,謝謝! – Xero

+1

好的,我的圖像太大了(像1800x1200),現在它像地獄一樣平滑= D謝謝 – Xero

3

這就是問題是因爲imageview需要很多內存。 解決方法就是這樣! 使新的文件夾drawable-nodpi。 將您的所有資源都放到該文件夾​​中。 希望這個幫助:)