开发者

Android View.getDrawingCache scale bitmap incorrect

开发者 https://www.devze.com 2023-01-24 12:12 出处:网络
I am creating a list view for message of different heights. The views are xml layout which are setup to layout the same on all resolution screens. To increase performance I am converting these view in

I am creating a list view for message of different heights. The views are xml layout which are setup to layout the same on all resolution screens. To increase performance I am converting these view into a bitmap image by calling View.getDrawingCache(). I am getting the Bitmap image but it seems to be scaling the text, especially in the high resolution screens. This is leaving the text a little blurry and in some case it is also being cut off at the edges. If I layout the View rather than the bitmap image, everything is scaled correctly but I am not getting the performance i desire. My item xml layout looks like this:

Xml Item View:

<?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>

View Measure Snippet:

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_WIDT开发者_开发知识库H);
child.measure(MeasureSpec.EXACTLY | itemWidth, MeasureSpec.UNSPECIFIED);

I have also added the snippet of code preforming the measurement of the view. Does anyone know how to prevent the text from scaling?


Ok... folks I figure it out. It was really simple and should have know this from the beginning. The solution is to make sure you add the to the AndroidManifest.xml. I set the supported resolution to any because my xml layout files are designed to automation re-size.

0

精彩评论

暂无评论...
验证码 换一张
取 消