3D Carousel in Android

3D Carousel for Android?

The closest thing I've seen is probably this. It's a modified GalleryView with image transforms applied to get the effects. Applying different transforms I think you could probably do what you're looking for.

Creating 3D image slider for Android and iOS

Here is a good staring point:

iOS

iCarousel

iCarousel

Android

SimpleInfiniteCarousel

Sample Image

CarouselViewProject

CarouselViewProject

How to Make an Android 3D Carousel Drawable

I was able to create the following carousel:

Sample Image

The code for it is:

@Override
public void draw(Canvas canvas) {

if (paintBackground == null) { // Just starting
paintBackground = new Paint();
paintBackground.setStyle(Paint.Style.FILL);
paintBackground.setColor(Color.BLUE);
}

// ######## CRUCIAL - START - Modify constants with care!

// Decreasing chord denominator makes carousel bigger, while increasing it
// makes front side contain more squares (but gets smaller)

float HALF_CHORD_WIDTH = canvas.getWidth()/31f; // Width of each square
float RADIUS = HALF_CHORD_WIDTH; // Radius of carousel
float CAMERA_MULT = HALF_CHORD_WIDTH/10f;

// ######## CRUCIAL - END

float INTERIOR_ANGLE = 30;

INTERIOR_ANGLE %= 360;
int numObjects = (int) (360 / INTERIOR_ANGLE);

for (int i = 0; i < numObjects; i++) {

if (i % 4 == 0) paintBackground.setColor(Color.YELLOW);
if (i % 4 == 1) paintBackground.setColor(Color.GREEN);
if (i % 4 == 2) paintBackground.setColor(Color.BLUE);
if (i % 4 == 3) paintBackground.setColor(Color.GRAY);
paintBackground.setAlpha(128);

float theta = INTERIOR_ANGLE * i;
double rad = Math.toRadians(theta);

float circleX = (float) (RADIUS * Math.sin(rad));
float circleZ = (float) (RADIUS * Math.cos(rad));

canvas.save();
canvas.translate(canvas.getWidth() / 2, canvas.getHeight() / 2);

Camera camera = new Camera();
camera.save();

camera.translate(circleX*CAMERA_MULT, 0, -circleZ*CAMERA_MULT);
camera.rotateY(theta);

camera.applyToCanvas(canvas);
camera.restore();

canvas.drawRect(
-HALF_CHORD_WIDTH,
-HALF_CHORD_WIDTH,
HALF_CHORD_WIDTH,
HALF_CHORD_WIDTH,
paintBackground);

canvas.restore();
}
}

Vertical 3dCarousel animation in android?

i have achieved this animation.

Below is the link for horizontal carousel animation which is most popular.

Androd 3d carousel animation

Now, here is the changes to achieve vertical carousel animation from above animation.

Carousel.java

  1. onFling : Change velocityX To velocityY

  2. onScroll : Change trackMotionScroll(/* -1 * / (int) distanceX); To trackMotionScroll(/ -1 * */ (int) distanceY);

  3. scrollIntoSlots : change "if (angle != 0.0f)" to "if (Math.abs(angle) > 4)"

  4. Calculate3DPosition :

    angleOffset = angleOffset * (float) (Math.PI / 180.0f);

        float x = (screenWidth - child.getWidth())/2;       
    float y = (float) (diameter / 2 * Math.sin(angleOffset)) + diameter / 2 - child.getWidth() / 2;
    float z = diameter*2 * (1.0f - (float) Math.cos(angleOffset));

    child.setItemX(x);
    child.setItemZ(z);
    child.setItemY(y-(screenHeight - child.getHeight())/2);

Enjoy carousel animation.

Android 3d carousel increase size of front image when we rotate

To just increase the size of the Selected Image change the Z coordinate in Carousal.java.

 private void Calculate3DPosition(CarouselItem child, int diameter, float angleOffset){

angleOffset = angleOffset * (float)(Math.PI/180.0f);

float x = - (float)(diameter/2 * android.util.FloatMath.sin(angleOffset)) + diameter/2 - child.getWidth()/2;
float z = diameter/2 * (1.0f - (float)android.util.FloatMath.cos(angleOffset));
float y = - getHeight()/2 + (float) (z * android.util.FloatMath.sin(mTheta));

child.setItemX(x);
child.setItemZ(z-200);//Add how much size you want for Z axis.
child.setItemY(y);

}


Related Topics



Leave a reply



Submit