我有一個活動,共包含4個圖像。它們都與1080x1920設備的分辨率相匹配。當我使用這些圖像(這些圖像通過XML直接加載到我的活動中)運行該活動時,它會在我的Genymotion模擬器中運行極其緩慢的,並且在真實的Android設備上運行滯後。
這裏是設置:活動運行緩慢,幾個ImageView-s
<android.support.design.widget.AppBarLayout
...>
<android.support.design.widget.CollapsingToolbarLayout
...>
<LinearLayout
android:layout_width="match_parent"
android:layout_height="200dp"
android:orientation="vertical"
app:layout_collapseMode="parallax">
<ImageView
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/imageView"
android:src="@drawable/shot_header"
android:scaleType="centerCrop" />
</LinearLayout>
<android.support.v7.widget.Toolbar
.../>
</android.support.design.widget.CollapsingToolbarLayout>
</android.support.design.widget.AppBarLayout>
第一圖像處於CollapsingToolbarlayout。該圖像的分辨率爲1080x649 PNG。
的content_activity:
此圖片填充母width.It的分辨率爲1080x772 PNG。
<ImageView
android:layout_width="match_parent"
android:layout_height="250dp"
android:id="@+id/main_image"
android:layout_below="@+id/shot_error_field"
android:src="@drawable/forehand_midpng"
android:adjustViewBounds="true"
android:scaleType="centerCrop"
android:layout_marginTop="15dp"/>
其他2個圖像是在一個的LinearLayout,其分辨率爲500x399
<LinearLayout
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_below="@+id/main_image">
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/imageView3"
android:src="@drawable/forehand_mid_wrong"
android:layout_weight="1"/>
<View
android:layout_width="0dp"
android:layout_height="1dp"
android:layout_weight="1" >
</View>
<ImageView
android:layout_width="150dp"
android:layout_height="150dp"
android:id="@+id/imageView4"
android:src="@drawable/forehand_mid_wrong"
android:layout_weight="1"/>
</LinearLayout>
總之,我有4個ImageViews的活動,填入適當大小的圖像,這應該現代Android設備沒有問題。問題是由於高內存消耗,此活動運行非常緩慢且滯後。
我做錯了什麼?我怎樣才能進一步優化這些圖像?
我看着其他線程-out of memory issue,但似乎沒有提出解決這樣的問題。
ImageView的一般不喜歡大的圖像。 –
你用'android:largeHeap =「true」'嘗試嗎?這是不值得推薦的,但如果沒有任何作用,它可能是有幫助的。 – Stanojkovic
問題是圖像分辨率..善意調整大小 –