Ich wollte eine Android MapActivity mit der Karte in einer Ansicht erstellen, die umgedreht und dann in einer anderen Ansicht konfiguriert werden konnte, und dann wieder auf die Karte zurückkippen. Die Lösung, die ich entwickelt habe, funktioniert, aber ich frage mich, ob es einen besseren Weg dafür gibt.Bessere Implementierung von Rotate3dAnimation in Android ViewFlipper
ich die Rotate3DAnimation Klasse aus dem Android ApiDemos kopiert, und erklärte, diese an der Spitze meiner MapActivity Klasse:
private MapView mMapView;
private ViewFlipper mFlipper;
private Rotate3dAnimation mInMapAnimation;
private Rotate3dAnimation mInStgAnimation;
private Rotate3dAnimation mOutMapAnimation;
private Rotate3dAnimation mOutStgAnimation;
nächste in meiner onCreate Methode des MapActivity Ich tat dies:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.mapoverviewlayout);
// Initialize the map.
MapView mapView = (MapView) findViewById(R.id.mapview);
mapView.setBuiltInZoomControls(true);
// Obtain the view flipper.
mFlipper = (ViewFlipper)findViewById(R.id.mapviewflipper);
// Initialize the settings view and handle the setting clicks.
Button stgMapDone = (Button)findViewById(R.id.MapViewOptionsDone);
stgMapDone.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
UnitOverviewMapActivity.this.mFlipper.showNext();
}
});
}
Und schließlich habe ich eine Menü-Taste verwendet, um die entsprechenden Flip-Animationen auszuwählen. Ich tat dies, weil wenn die Karte um eine Richtung kippt, um die Einstellungsansicht zu öffnen, ich wollte, dass sie in die umgekehrte Richtung kippt, um die Einstellungsansicht auszublenden. Also in meinem onPrepareOptionsMenu (denn das ist, wo meine Taste war) Ich tat dies:
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
if (mInMapAnimation == null) {
mInMapAnimation = new Rotate3dAnimation(-90, 0, mMapView.getWidth()/2, mMapView.getHeight()/2, 0.0f, false);
mInMapAnimation.setDuration(1000);
mInMapAnimation.setStartOffset(1000);
}
if (mInStgAnimation == null) {
mInStgAnimation = new Rotate3dAnimation(90, 0, mMapView.getWidth()/2, mMapView.getHeight()/2, 0.0f, false);
mInStgAnimation.setDuration(1000);
mInStgAnimation.setStartOffset(1000);
}
if (mOutMapAnimation == null) {
mOutMapAnimation = new Rotate3dAnimation(0, -90, mMapView.getWidth()/2, mMapView.getHeight()/2, 0.0f, false);
mOutMapAnimation.setDuration(1000);
}
if (mOutStgAnimation == null) {
mOutStgAnimation = new Rotate3dAnimation(0, 90, mMapView.getWidth()/2, mMapView.getHeight()/2, 0.0f, false);
mOutStgAnimation.setDuration(1000);
}
if (mFlipper.getCurrentView().getId() == R.id.mapparentlayout) {
mFlipper.setInAnimation(mInStgAnimation);
mFlipper.setOutAnimation(mOutMapAnimation);
}
else {
mFlipper.setInAnimation(mInMapAnimation);
mFlipper.setOutAnimation(mOutStgAnimation);
}
return true;
}
Dies funktioniert gut, aber es scheint nur ineffizient. Ich (anscheinend fälschlicherweise) nahm an, dass das "Spiegeln" eine eingebaute Funktion des ViewFlipper-Containers wäre. Gibt es einen besseren oder effizienteren Weg, dies zu erreichen?