मेरे पास एक एंड्रॉइड एप्लिकेशन है और दो गतिविधियों के बीच स्विच करते समय मैं 3 डी संक्रमण लागू करना चाहता हूं ... मुझे विधि overridePendingTransition()
पता है लेकिन इसमें 3 डी के लिए कोई एनीमेशन नहीं है .. तो यह कैसे किया जा सकता है?एंड्रॉइड में दो गतिविधियों के बीच 3 डी संक्रमण कैसे लागू करें?
उत्तर
मैंने गतिविधियों के बीच 3 डी घन संक्रमण का उपयोग किया था। क्रेडिट रॉबर्ट हेम के पास जाता है जो इस कार्यक्रम के डेवलपर हैं।
नीचे छोटा सा अंश है
Activity1.java
package org.vipul;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Activity1 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity1);
Button switchActivityBtn = (Button) findViewById(R.id.bSwitchActivity);
switchActivityBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animatedStartActivity();
}
});
}
@Override
protected void onResume() {
// animateIn this activity
ActivitySwitcher.animationIn(findViewById(R.id.container),
getWindowManager());
super.onResume();
}
private void animatedStartActivity() {
// we only animateOut this activity here.
// The new activity will animateIn from its onResume() - be sure to
// implement it.
final Intent intent = new Intent(getApplicationContext(),
Activity2.class);
// disable default animation for new intent
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
ActivitySwitcher.animationOut(findViewById(R.id.container),
getWindowManager(),
new ActivitySwitcher.AnimationFinishedListener() {
@Override
public void onAnimationFinished() {
startActivity(intent);
}
});
}
}
Activity2.java
package org.vipul;
import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
public class Activity2 extends Activity {
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity2);
Button switchActivityBtn = (Button) findViewById(R.id.bSwitchActivity);
switchActivityBtn.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
animatedStartActivity();
}
});
}
@Override
protected void onResume() {
// animateIn this activity
ActivitySwitcher.animationIn(findViewById(R.id.container),
getWindowManager());
super.onResume();
}
private void animatedStartActivity() {
// we only animateOut this activity here.
// The new activity will animateIn from its onResume() - be sure to
// implement it.
final Intent intent = new Intent(getApplicationContext(),
Activity1.class);
// disable default animation for new intent
intent.addFlags(Intent.FLAG_ACTIVITY_NO_ANIMATION);
ActivitySwitcher.animationOut(findViewById(R.id.container),
getWindowManager(),
new ActivitySwitcher.AnimationFinishedListener() {
@Override
public void onAnimationFinished() {
startActivity(intent);
}
});
}
}
ActivitySwitcher.java
package org.vipul;
import android.view.Display;
import android.view.View;
import android.view.WindowManager;
import android.view.animation.AccelerateInterpolator;
import android.view.animation.Animation;
/**
* This ActivitySwitcher uses a 3D rotation to animate an activity during its
* start or finish.
*
* see: http://blog.robert-heim.de/karriere/android-startactivity-rotate-3d-
* animation-activityswitcher/
*
* @author Robert Heim
*
*/
public class ActivitySwitcher {
private final static int DURATION = 300;
private final static float DEPTH = 400.0f;
/* ----------------------------------------------- */
public interface AnimationFinishedListener {
/**
* Called when the animation is finished.
*/
public void onAnimationFinished();
}
/* ----------------------------------------------- */
public static void animationIn(View container, WindowManager windowManager) {
animationIn(container, windowManager, null);
}
public static void animationIn(View container, WindowManager windowManager,
AnimationFinishedListener listener) {
apply3DRotation(90, 0, false, container, windowManager, listener);
}
public static void animationOut(View container, WindowManager windowManager) {
animationOut(container, windowManager, null);
}
public static void animationOut(View container,
WindowManager windowManager, AnimationFinishedListener listener) {
apply3DRotation(0, -90, true, container, windowManager, listener);
}
/* ----------------------------------------------- */
private static void apply3DRotation(float fromDegree, float toDegree,
boolean reverse, View container, WindowManager windowManager,
final AnimationFinishedListener listener) {
Display display = windowManager.getDefaultDisplay();
final float centerX = display.getWidth()/2.0f;
final float centerY = display.getHeight()/2.0f;
final Rotate3dAnimation a = new Rotate3dAnimation(fromDegree, toDegree,
centerX, centerY, DEPTH, reverse);
a.reset();
a.setDuration(DURATION);
a.setFillAfter(true);
a.setInterpolator(new AccelerateInterpolator());
if (listener != null) {
a.setAnimationListener(new Animation.AnimationListener() {
@Override
public void onAnimationStart(Animation animation) {
}
@Override
public void onAnimationRepeat(Animation animation) {
}
@Override
public void onAnimationEnd(Animation animation) {
listener.onAnimationFinished();
}
});
}
container.clearAnimation();
container.startAnimation(a);
}
}
Rotate3dAnimation.java
package org.vipul;
import android.graphics.Camera;
import android.graphics.Matrix;
import android.view.animation.Animation;
import android.view.animation.Transformation;
/**
* An animation that rotates the view on the Y axis between two specified
* angles. This animation also adds a translation on the Z axis (depth) to
* improve the effect.
*/
public class Rotate3dAnimation extends Animation {
private final float mFromDegrees;
private final float mToDegrees;
private final float mCenterX;
private final float mCenterY;
private final float mDepthZ;
private final boolean mReverse;
private Camera mCamera;
/**
* Creates a new 3D rotation on the Y axis. The rotation is defined by its
* start angle and its end angle. Both angles are in degrees. The rotation
* is performed around a center point on the 2D space, definied by a pair of
* X and Y coordinates, called centerX and centerY. When the animation
* starts, a translation on the Z axis (depth) is performed. The length of
* the translation can be specified, as well as whether the translation
* should be reversed in time.
*
* @param fromDegrees
* the start angle of the 3D rotation
* @param toDegrees
* the end angle of the 3D rotation
* @param centerX
* the X center of the 3D rotation
* @param centerY
* the Y center of the 3D rotation
* @param reverse
* true if the translation should be reversed, false otherwise
*/
public Rotate3dAnimation(float fromDegrees, float toDegrees, float centerX,
float centerY, float depthZ, boolean reverse) {
mFromDegrees = fromDegrees;
mToDegrees = toDegrees;
mCenterX = centerX;
mCenterY = centerY;
mDepthZ = depthZ;
mReverse = reverse;
}
@Override
public void initialize(int width, int height, int parentWidth,
int parentHeight) {
super.initialize(width, height, parentWidth, parentHeight);
mCamera = new Camera();
}
@Override
protected void applyTransformation(float interpolatedTime, Transformation t) {
final float fromDegrees = mFromDegrees;
float degrees = fromDegrees
+ ((mToDegrees - fromDegrees) * interpolatedTime);
final float centerX = mCenterX;
final float centerY = mCenterY;
final Camera camera = mCamera;
final Matrix matrix = t.getMatrix();
camera.save();
if (mReverse) {
camera.translate(0.0f, 0.0f, mDepthZ * interpolatedTime);
} else {
camera.translate(0.0f, 0.0f, mDepthZ * (1.0f - interpolatedTime));
}
camera.rotateY(degrees);
camera.getMatrix(matrix);
camera.restore();
matrix.preTranslate(-centerX, -centerY);
matrix.postTranslate(centerX, centerY);
}
}
Activity1.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:background="#003300"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="@string/hello" />
<Button
android:id="@+id/bSwitchActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="switch activity" />
</LinearLayout>
Activity2.xml
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/container"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<Button
android:id="@+id/bSwitchActivity"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="back" />
</LinearLayout>
प्रकट प्रविष्टियों
<activity
android:name=".Activity1"
android:label="@string/app_name" >
<intent-filter>
<action android:name="android.intent.action.MAIN" />
<category android:name="android.intent.category.LAUNCHER" />
</intent-filter>
</activity>
<activity
android:name=".Activity2"
android:label="Activity 2" >
</activity>
कोड के लिए बहुत बहुत धन्यवाद .... यह बिल्कुल काम कर रहा है – user1438128
यदि यह आपकी समस्या का समाधान करता है तो आप उत्तर –
को स्वीकार कर इस प्रश्न को बंद कर सकते हैं यह घन नहीं है। – Butters
यहाँ रिवर्स एनीमेशन कार्यक्षमता के साथ @Vipul शाह कोड का विस्तार है
ऐड निम्नलिखित "ActivitySwitcher"
public static void animationInReverse(View container, WindowManager windowManager) {
animationInReverse(container, windowManager, null);
}
public static void animationInReverse(View container, WindowManager windowManager, AnimationFinishedListener listener) {
apply3DRotation(-90, 0, false, container, windowManager, listener);
}
public static void animationOutReverse(View container, WindowManager windowManager) {
animationOut(container, windowManager, null);
}
public static void animationOutReverse(View container, WindowManager windowManager, AnimationFinishedListener listener) {
apply3DRotation(0, 90, true, container, windowManager, listener);
}
और पहली गतिविधि
में जोड़ने के लिए में विधि@Override
protected void onResume() {
if (isFromOncreate) {
isFromOncreate = false;
ActivitySwitcher.animationIn(findViewById(R.id.container), getWindowManager());
} else {
ActivitySwitcher.animationInReverse(findViewById(R.id.container), getWindowManager());
}
super.onResume();
}
- 1. एंड्रॉइड में दो गतिविधियों के बीच स्लाइड एनीमेशन कैसे लागू करें?
- 2. एंड्रॉइड गतिविधियों के बीच स्वाइप करें ViewPager
- 3. अक्षम संक्रमण एनीमेशन गतिविधियों के बीच
- 4. डी 3 संक्रमण
- 5. एंड्रॉइड में गतिविधियों के बीच साझा वरीयता तक कैसे पहुंचे?
- 6. डी 3 माउसओवर संक्रमण "अटक गया"
- 7. गतिविधि के बीच 3 डी एनीमेशन एंड्रॉयड
- 8. एंड्रॉइड गतिविधियों के बीच स्ट्रिंग सरणी पास करना
- 9. एंड्रॉइड 3 डी एनीमेशन
- 10. आईफोन दृश्य में 3 डी रोटेशन लागू करें
- 11. 3 डी
- 12. एंड्रॉइड मेनिफेस्ट फ़ाइल में अपनी गतिविधियों के साथ दो पैकेज कैसे घोषित करें?
- 13. एंड्रॉइड: कई गतिविधियों में मेनू प्रदर्शित करें
- 14. गतिविधियों के बीच एक वस्तु साझा करना
- 15. एंड्रॉइड ओपनजीएल 3 डी पिकिंग
- 16. गतिविधियों के एंड्रॉइड स्टैक को कैसे साफ़ करें?
- 17. एकाधिक गतिविधियों के बीच समान डेटा कैसे साझा करें
- 18. कैसे डी 3
- 19. 3 डी
- 20. ज़ेंड_Mail और = 0 डी = 0 ए = 3 डी = 3 डी = 3 डी = 3 डी = 3 डी
- 21. ओबीजे बनाम 3 डी एस - एंड्रॉइड 3 डी विकास
- 22. क्या गतिविधियों के बीच संक्रमण करते समय उपयोग करने के लिए कोई फ़्लिप एनीमेशन उपलब्ध है?
- 23. एकाधिक गतिविधियों के बीच एक एंड्रॉइड सेवा से कैसे जुड़े रहें?
- 24. एंड्रॉइड एप्लिकेशन में वापस स्टैक गतिविधियों को कैसे ढूंढें?
- 25. विभिन्न एंड्रॉइड गतिविधियों के बीच डेटा (ऑब्जेक्ट्स) का आदान-प्रदान कैसे करें?
- 26. 3 डी प्लॉटिंग में 3 डी प्लॉटिंग में 3 डी प्लॉटिंग में matplotlib रंग contour
- 27. दो 2 डी अंकों से एक 3 डी बिंदु पुनर्निर्माण?
- 28. कैसे 3 डी स्पेस
- 29. दो एंड्रॉइड फोन के बीच दूरी
- 30. डी 3
इसे देखें nswer [यहां क्लिक करें] [1]। यह हो सकता है कि आप क्या चाहते [1]: http://stackoverflow.com/questions/5339907/3d-cube-transition-in-android – Phobos
मैं इसे लागू करने की कोशिश की ... लेकिन मैं वास्तव में नहीं कर सकते इसे प्राप्त करें..क्या आपने इस उदाहरण को व्यक्तिगत रूप से – user1438128
नंबर पर आजमाया है लेकिन नीचे दिए गए क्यूरेटेड उत्तर को देखें। – Phobos