2010-11-12 106 views
0

我正在爲不同高度的消息創建列表視圖。視圖是xml佈局,它們在所有分辨率屏幕上設置爲佈局相同。爲了提高性能,我通過調用View.getDrawingCache()將這些視圖轉換爲位圖圖像。我正在獲取位圖圖像,但它似乎在縮放文本,尤其是在高分辨率屏幕中。這會使文本變得模糊,並且在某些情況下也會在邊緣被切斷。如果我佈置視圖而不是位圖圖像,所有內容都可以正確縮放,但我沒有獲得我想要的性能。我的項目XML佈局看起來是這樣的:Android View.getDrawingCache縮放位圖不正確

XML項查看:

<?xml version="1.0" encoding="utf-8"?> 
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent" 
    android:padding="5px" 
    android:background="#FFFFFF"> 
    <ImageView android:id="@+id/contact_photo" 
     android:layout_width="48dip" 
     android:layout_height="48dip"/> 
    <ImageView android:id="@+id/network_icon" 
     android:layout_alignParentRight="true" 
     android:layout_width="16dip" 
     android:layout_height="16dip"/> 
    <TextView android:id="@+id/created_date" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="14sp" 
    android:layout_toLeftOf="@+id/network_icon" 
    android:textColor="#000000"/> 
    <TextView android:id="@+id/sender_name" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="16sp" 
     android:layout_toRightOf="@+id/contact_photo" 
     android:ellipsize="end" 
     android:singleLine="true" 
     android:textColor="#000000"/> 
    <TextView android:id="@+id/summary" 
     android:layout_below="@+id/sender_name" 
     android:layout_toRightOf="@+id/contact_photo" 
     android:layout_width="wrap_content" 
     android:layout_height="wrap_content" 
     android:textSize="14sp" 
     android:maxLines="4" 
     android:textColor="#000000" /> 
    <LinearLayout 
     android:id="@+id/AttachmentLayout" 
     android:layout_below="@+id/summary" 
     android:layout_height="wrap_content" 
     android:orientation="horizontal" 
     android:layout_width="wrap_content"/> 
</RelativeLayout> 

查看測量段:

LayoutParams params = child.getLayoutParams(); 
if (params == null) { 
    params = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT); 
} 
final int index = layoutMode == LAYOUT_MODE_ABOVE ? 0 : -1; 
child.setDrawingCacheEnabled(true); 
addViewInLayout(child, index, params, true); 

final int itemWidth = (int)(getWidth() * ITEM_WIDTH); 
child.measure(MeasureSpec.EXACTLY | itemWidth, MeasureSpec.UNSPECIFIED); 

我也加入了代碼預成型的測量片斷風景。有誰知道如何防止文本縮放?

回答

0

好的......夥計們我知道了。這非常簡單,應該從一開始就知道這一點。解決方案是確保你添加到AndroidManifest.xml中。我將支持的分辨率設置爲任何因爲我的xml佈局文件設計爲自動重新大小。