【问题标题】:Android View.getDrawingCache scale bitmap incorrectAndroid View.getDrawingCache 缩放位图不正确
【发布时间】:2010-11-12 05:55:12
【问题描述】:

我正在为不同高度的消息创建一个列表视图。视图是 xml 布局,设置为在所有分辨率屏幕上布局相同。为了提高性能,我通过调用 View.getDrawingCache() 将这些视图转换为位图图像。我正在获取位图图像,但它似乎正在缩放文本,尤其是在高分辨率屏幕中。这使文本有点模糊,在某些情况下,它也会在边缘被切断。如果我布局视图而不是位图图像,一切都正确缩放,但我没有得到我想要的性能。我的项目 xml 布局如下所示:

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);

我还添加了执行视图测量的代码的 sn-p。有谁知道如何防止文本缩放?

【问题讨论】:

    标签: android listview bitmap scale


    【解决方案1】:

    好的……伙计们,我想通了。这真的很简单,应该从一开始就知道这一点。解决方案是确保将其添加到 AndroidManifest.xml。我将支持的分辨率设置为任意,因为我的 xml 布局文件旨在自动调整大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-09-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多