In case you have 2d images for different angles (If you have gif image, you can extract frames from it), you can do in following way:
Define an axml in drawable folder:
image_3D_images.xml
<level-list xmlns:android="http://schemas.android.com/apk/res/android">
<item android:maxLevel="0" android:drawable="@drawable/bg_01" />
<item android:maxLevel="1" android:drawable="@drawable/bg_02" />
<item android:maxLevel="2" android:drawable="@drawable/bg_03" />
<item android:maxLevel="3" android:drawable="@drawable/bg_04" />
<item android:maxLevel="4" android:drawable="@drawable/bg_05" />
</level-list>
Then create your layout with an imageview like this:
activity_3d_view.xml:
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<ImageView
android:id="@+id/santafe3dview"
android:layout_gravity="center"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:src="@drawable/image_3d_images"
android:scaleType="fitXY"
/>
</RelativeLayout>
Then in you activity write following code :
Launcher3DViewActivity.java:
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mContext = this;
setContentView(R.layout.activity_3d_view);
m360DegreeImageView = (ImageView)findViewById(R.id.santafe3dview);
}
@Override
public boolean onTouchEvent(MotionEvent event){
int action = MotionEventCompat.getActionMasked(event);
switch(action) {
case (MotionEvent.ACTION_DOWN) :
mStartX = (int)event.getX();
mStartY = (int)event.getY();
return true;
case (MotionEvent.ACTION_MOVE) :
mEndX = (int)event.getX();
mEndY = (int)event.getY();
if((mEndX - mStartX) > 3) {
mImageIndex++;
if(mImageIndex > 56 )
mImageIndex = 0;
m360DegreeImageView.setImageLevel(mImageIndex);
}
if((mEndX - mStartX) < -3) {
mImageIndex--;
if(mImageIndex <0)
mImageIndex = 56;
m360DegreeImageView.setImageLevel(mImageIndex);
}
mStartX = (int)event.getX();
mStartY = (int)event.getY();
return true;
case (MotionEvent.ACTION_UP) :
mEndX = (int)event.getX();
mEndY = (int)event.getY();
return true;
case (MotionEvent.ACTION_CANCEL) :
return true;
case (MotionEvent.ACTION_OUTSIDE) :
return true;
default :
return super.onTouchEvent(event);
}
}