我有一個Android應用程序,它在HoneyComb上運行良好,但在ICS上運行不正常。我有谷歌地圖,不僅如此,我創建使用圓圈雷達效果頂部(圈子半徑不斷增加給樣的水浪效果。)的代碼如下:Android視圖/ canvas drawCircle問題與ICS
class ShowRadar extends AsyncTask<Void, Void, RadarView>
{
private Context ctx;
private int radius;
private GeoPoint gp;
private MapView mv;
ShowRadar(Context ctxt, MapView mv, int radius, GeoPoint gp)
{
this.ctx = ctxt;
this.radius = radius;
this.gp = gp;
this.mv = mv;
}
@Override
protected RadarView doInBackground(Void... params)
{
RadarView rdView = new RadarView(ctx, mv, gp, radius);
LayoutParams lp = new LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT);
rdView.setLayoutParams(lp);
return rdView;
}
@Override
protected void onPostExecute(RadarView result) {
if(this.radius <= 10000)
{
if(this.radius < 50)
{
this.radius += 50;
}
else if(this.radius < 100)
{
this.radius += 100;
}
else if(this.radius < 500)
{
this.radius += 500;
}
else
{
this.radius += 1000;
}
}
else
this.radius = 10;
if(radarUpdated || radarCount > 1000)
{
if(radarCount > 1000 && !radarUpdated)
{
Toast.makeText(mContext, "Delay in response, wait a while", Toast.LENGTH_SHORT).show();
}
radarCount = 0;
if (oldrd != null) {
rel.removeView(oldrd);
oldrd = null;
}
}
else
{
radarCount++;
if(oldrd != null)
{
rel.removeView(oldrd);
}
oldrd = result;
rel.addView(result);
new ShowRadar(ctx, mv, this.radius, gp).execute();
}
}
}
new ShowRadar(mContext, mapView, 10, center).execute();
並在下面的代碼RadarView
public class RadarView extends View {
private int circleRadius = 500;
private GeoPoint p;
public RadarView(Context context) {
super(context);
init();
}
public RadarView(Context context, MapView mv, GeoPoint pt, Integer radius)
{
super(context);
this.mapView = mv;
this.p = pt;
this.circleRadius = radius;
init();
}
private void init(){
paint = new Paint();
paint.setColor(Color.GREEN);
paint.setStrokeWidth(10);
paint.setStyle(Paint.Style.STROKE);
}
@Override
protected void onDraw(Canvas canvas) {
Projection projection = mapView.getProjection();
Point pt = new Point();
projection.toPixels(p, pt);
float circleRadius = metersToRadius(this.circleRadius, mapView, (double)p.getLatitudeE6()/1E6);
Paint circlePaint = new Paint(Paint.ANTI_ALIAS_FLAG);
circlePaint.setARGB(150, 12, 232, 91);
circlePaint.setStyle(Style.STROKE);
circlePaint.setStrokeWidth(10);
if(canvas.isHardwareAccelerated())
{
mapView.setLayerType(View.LAYER_TYPE_SOFTWARE, null);
}
canvas.drawCircle((float)pt.x, (float)pt.y, circleRadius, circlePaint);
super.onDraw(canvas);
}
public static int metersToRadius(float meters, MapView map, double latitude) {
return (int) (map.getProjection().metersToEquatorPixels(meters) * (1/ FloatMath.cos((float) Math.toRadians(latitude))));
}
}
我已經通過各種論壇上消失了,發現ICS默認激活HardwareAcceleration所以我增加了以下清單中的,但沒有幫助標籤。任何人 都可以告訴我這裏出了什麼問題。
<application
android:hardwareAccelerated="false"
....
</application>