问题是添加到main.xml的所有视图都正确翻转 - 在最后一个视图进入第一个视图之后,在第一个 - 最后一次之后,它的四舍五入,但是如果我使用ViewFlipper类的方法addView添加视图它不会翻转“四舍五入”它会停在它上面并做一些不正确的动画,它不会进入下一个视图,只有在完成只有1次翻转时才会转到前一个视图。 请说明如何使其作为圆形1-> 2-> 3-> 1起作用。 这是鳍状肢实现的代码:
public class Activity1 extends Activity implements OnTouchListener{
float downXValue;
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
// Set main.XML as the layout for this Activity
// Add these two lines
LinearLayout layMain = (LinearLayout) findViewById(R.id.layout_main);
layMain.setOnTouchListener((OnTouchListener) this);
}
public boolean onTouch(View arg0, MotionEvent arg1) {
// Get the action that was done on this touch event
switch (arg1.getAction())
{
case MotionEvent.ACTION_DOWN:
{
// store the X value when the user's finger was pressed down
downXValue = arg1.getX();
break;
}
case MotionEvent.ACTION_UP:
{
// Get the X value when the user released his/her finger
float currentX = arg1.getX();
View view = new View(this);
//HERE IS DECLARATION OF VIEW WHICH I NEED TO ADD
GraphicsView myview=new GraphicsView(this);
// going backwards: pushing stuff to the right
if (downXValue < currentX)
{
// Get a reference to the ViewFlipper
ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
vf.addView(myview);
// Set the animation
vf.setInAnimation(view.getContext(), R.anim.push_right_in);
vf.setOutAnimation(view.getContext(), R.anim.push_right_out);
// Flip!
vf.showNext();
}
// going forwards: pushing stuff to the left
if (downXValue > currentX)
{
// Get a reference to the ViewFlipper
ViewFlipper vf = (ViewFlipper) findViewById(R.id.details);
//HERE I'M ADDING IT
vf.addView(myview);
// Set the animation
vf.setInAnimation(view.getContext(), R.anim.push_left_in);
vf.setOutAnimation(view.getContext(), R.anim.push_left_out);
// Flip!
vf.showPrevious();
}
break;
}
}
// if you return false, these actions will not be recorded
return true;
}
请帮忙。并且如果可能的话,回答plz在main.xml中添加对象,我在代码中定义的像myview是GraphicsView的类对象,它从View扩展。
此致 Keem
答案 0 :(得分:-1)
根据您发布的代码,在您的代码中,您可以在触摸事件中动态添加视图,以便您多次触摸设备屏幕,OnTouch()调用以及每次触摸调用此...
GraphicsView myview = new GraphicsView(this);
而且这个.. ViewFlipper vf =(ViewFlipper)findViewById(R.id.details);
vf.addView(MyView的);
所以每次触摸你添加一个视图,这可能就是为什么你没有正确翻转。
对于您的解决方案,您应该遵循正确的流程 - 可能如下