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
Android
SimpleInfiniteCarousel
CarouselViewProject
How to Make an Android 3D Carousel Drawable
I was able to create the following carousel:
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
onFling : Change velocityX To velocityY
onScroll : Change trackMotionScroll(/* -1 * / (int) distanceX); To trackMotionScroll(/ -1 * */ (int) distanceY);
scrollIntoSlots : change "if (angle != 0.0f)" to "if (Math.abs(angle) > 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
How to Add Radio Button Dynamically as Per The Given Number of Counts
How to Fetch Data from a Web Server in an Android Application
Flutter Insecure Http Is Not Allowed by Platform
Android: How to Download a Video File to Sd Card
Android Service to Check Internet Connectivity
Exception When Opening Parse Push Notification
Speechrecognizer Causes Anr... I Need Help with Android Speech API
Backup/Restore Sqlite Db in Android
Android, How to Exec a SQL File in Sqlitedatabase
Android: Share Session Between Webview and Httpclient
How to Add a Custom Item to a Navigationview with a Menu Layout
Set View Text Align at Center in Spinner in Android
Putting Screen Densities into The Correct Bucket
Conversion from String to JSON Object Android
How to Specify Location of Debug Keystore for Android Ant Debug Builds