2

我刚刚在 Galaxy Nexus 上升级了 Android 4.2,ListView 似乎比以前在 4.1 上要慢。这种 bindView 方法在 4.1 上非常快速,在新的 4.2 上我看到了小故障。我曾尝试在 中显式启用硬件加速AndroidManifest.xml,但这并没有多大帮助。People (Contacts) 应用程序在 4.2 上完美运行,我猜这也是由 extended 实现的android.support.v4.widget.CursorAdapter。我也已经尝试在没有明显改善的情况下进行android.support.v4.widget.CursorAdapter更改android.widget.CursorAdapter

@Override
public void bindView(View view, Context context, Cursor cursor) {
    final ViewHolder holder = (ViewHolder) view.getTag();
    holder.nameView.setText(cursor.getString(mStreetColumnIndex));
    holder.townView.setText(cursor.getString(mTownColumnIndex));
    if (mDistanceColumn != null) {
        float distance = cursor.getFloat(mDistanceColumn);
        String distanceUnit;
        if (distance >= 1000) {
            distance /= 1000;
            distanceUnit = " km";
        } else {
            distanceUnit = " m";
        }
        String decimalString = mDecimalFormat.format(distance);
        holder.distanceView.setText(decimalString + distanceUnit);
        holder.distanceView.setVisibility(View.VISIBLE);
    } else {
        holder.distanceView.setVisibility(View.GONE);
    }

    // read only brand first letter to be faster
    cursor.copyStringToBuffer(mBrandColumnIndex, mBuffer);
    if (mBuffer.sizeCopied > 0) {
        if (mBuffer.data[0] == 'a') {
            holder.logoImgView.setImageResource(R.drawable.agip);
        } else {
            holder.logoImgView.setImageResource(R.drawable.papoil);
        }
    } else {
        holder.logoImgView.setVisibility(View.INVISIBLE);
    }
}

编辑:添加行布局

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:minHeight="@dimen/row_height"
            android:background="@drawable/bg_list_selector"
            android:layout_marginRight="@dimen/screen_padding"
            android:layout_marginLeft="@dimen/screen_padding"
            android:paddingLeft="@dimen/screen_padding">
<LinearLayout
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:layout_alignParentLeft="true"
        android:layout_marginRight="@dimen/screen_padding"
        android:layout_toLeftOf="@+id/txtDistance"
        android:orientation="vertical"
        >
    <TextView
            android:id="@+id/txtName"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/list_text_primary_size"
            android:textStyle="bold"
            />
    <TextView
            android:id="@+id/txtTown"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:textSize="@dimen/list_text_primary_size"
            />
</LinearLayout>
<TextView
        android:id="@+id/txtDistance"
        android:layout_toLeftOf="@+id/imgLogo"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_centerVertical="true"
        android:textColor="@color/grey_dark"
        android:textSize="13sp"
        android:textStyle="bold"
        android:layout_marginRight="@dimen/screen_padding"/>
<ImageView
        android:id="@+id/imgLogo"
        android:layout_alignParentRight="true"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:src="@drawable/agip"
        android:background="@color/grey_dark"
        />
</RelativeLayout>

编辑 2:这是使用 http://goo.gl/Yoe1u 制作traceview http://goo.gl/UmS3w

4

1 回答 1

1

这是由于windowBackground过于复杂造成的,即:

<?xml version="1.0" encoding="utf-8"?>
<layer-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:drawable="@drawable/bg_repeat">
</item>
<item>
    <shape>
        <gradient android:startColor="#0affffff" android:endColor="#0a000000"
                  android:type="radial" android:gradientRadius="500"/>
    </shape>
</item>
<item>
    <shape>
        <gradient android:startColor="#1effffff" android:endColor="#1e000000"
                  android:type="linear" android:angle="270"/>
    </shape>
</item>
</layer-list>

和 bg_repeat.xml:

<?xml version="1.0" encoding="utf-8"?>
<bitmap xmlns:android="http://schemas.android.com/apk/res/android"
    android:src="@drawable/bg"
    android:tileMode="repeat"/>

谢谢大家的帮助!

于 2012-11-14T09:53:41.377 回答