Witam chcialbym skonfigurować płynne przejście pomiędzy dwoma widokami. Widoki nie są definiowane w pliku xml ale jako stworzone przeze mnie klasy. Wygląda to przykładowo tak:
Pierwszy widok:
public class first extends View {
public first(Context context) {
super(context);
}
@Override
protected void onDraw(Canvas canvas) {
super.onDraw(canvas);
Paint paint = new Paint();
paint.setColor(23445679);
Rect rect = new Rect();
rect.set(0, 0, 100, 100);
canvas.drawRect(rect, paint);
}
}
Druga klasa widoku jest praktycznie taka sama. Kod mojej aktywności zamieszczam poniżej:
public class Main extends Activity {
private ViewFlipper vf;
private float lastX;
private first firstv;
private second secondv;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
vf = (ViewFlipper) findViewById(R.id.view_flipper);
firstv = new first(this);
secondv = new second(this);
vf.addView(firstv);
vf.addView(secondv);
}
@Override
public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction())
{
case MotionEvent.ACTION_DOWN:
{
lastX = touchevent.getX();
break;
}
case MotionEvent.ACTION_UP:
{
float currentX = touchevent.getX();
if (lastX < currentX)
{
if (vf.getDisplayedChild()==0) break;
vf.showNext();
}
if (lastX > currentX)
{
if (vf.getDisplayedChild()==1) break;
vf.showPrevious();
}
break;
}
}
return false;
}
}
Jak widać do przejścia chciałem użyć klasy ViewFlipper. Ale w żaden sposób nie wiedzi mi tych widoków. Prosze o jakąś wskazówkę.