Android View.getDrawingCache缩放位图不正确

问题描述:

我正在为不同高度的消息创建列表视图。视图是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); 

我也加入了代码预成型的测量片断风景。有谁知道如何防止文本缩放?

好的......伙计们我知道了。这非常简单,应该从一开始就知道这一点。解决方案是确保你添加到AndroidManifest.xml中。我将支持的分辨率设置为任何因为我的xml布局文件设计为自动重新大小。