ViewFlipper兼容性

时间:2013-03-06 03:40:01

标签: android android-layout compatibility

我的应用程序在某些版本和一些建议中不起作用。

例如:

  • 三星4.04 - 工程
  • 摩托罗拉4.04 - 破碎
  • 三星2.3.6 - 作品
  • LG 2.2.2 - 破碎

如果有人知道发生了什么,请告诉我。我觉得这一定很简单。

我的清单宣布min sdk = 4且max = 16。

我使用ViewFlipper来改变布局,也许这就是问题所在。该应用仅在到达此部分时关闭。

抱歉没有崩溃日志。

public class ImagesActivity extends Activity {

private SensorManager mSensorManager;
private ShakeEventListener mSensorListener;
private ViewFlipper mFlipper;
private Animation Animation, Animation2, Animation3, Animation4;
private Random randomGenerator = new Random();

@SuppressLint("NewApi")
@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.imagesview);

    final LinearLayout myLayout = (LinearLayout) findViewById(R.id.images_view);

    //declaração ViewFlipper das telas
    mFlipper = (ViewFlipper) findViewById(R.id.mFlipper1);

     //declaração das var para o evento Shake
     mSensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
     mSensorListener = new ShakeEventListener(); 

     //declaração anim 1 - Slide from left
     Animation = (Animation) AnimationUtils.loadAnimation(this, R.anim.slideleft);
     Animation.setFillAfter(true);

     //declaração anim 2 - Slide from right
     Animation2 = (Animation) AnimationUtils.loadAnimation(this, R.anim.slideright);
     Animation.setFillAfter(true);

     //declaração anim 3 - Slide from down
     Animation3 = (Animation) AnimationUtils.loadAnimation(this, R.anim.slideup);
     Animation.setFillAfter(true);

     //declaração anim 4 - Slide from up
     Animation4 = (Animation) AnimationUtils.loadAnimation(this, R.anim.slidedown);
     Animation.setFillAfter(true);

     //Event Shake para execução das telas random
     mSensorListener.setOnShakeListener(new ShakeEventListener.OnShakeListener() {
          public void onShake() {
              int random;
              Random RandomView = new Random();
                 int nextViewIndex = RandomView.nextInt(18);
                 while (nextViewIndex == mFlipper.getDisplayedChild()) {
                     nextViewIndex = RandomView.nextInt(18);
                 }
                random = randomGenerator.nextInt(4);

                if(random ==1)
                    myLayout.startAnimation(Animation);
                else if(random ==2)
                    myLayout.startAnimation(Animation2);
                else if(random ==3)
                    myLayout.startAnimation(Animation3);
                else
                    myLayout.startAnimation(Animation4);

                 mFlipper.setDisplayedChild(nextViewIndex);
          }
          });
}


@Override
public boolean onOptionsItemSelected(MenuItem item) {
    switch (item.getItemId()) {
    case android.R.id.home:
        NavUtils.navigateUpFromSameTask(this);
        return true;
    }
    return super.onOptionsItemSelected(item);
}

@Override
  public void onResume() {
    super.onResume();
    mSensorManager.registerListener(mSensorListener,
        mSensorManager.getDefaultSensor(Sensor.TYPE_ACCELEROMETER),
        SensorManager.SENSOR_DELAY_UI);
  }

  @Override
  public void onPause() {
    mSensorManager.unregisterListener(mSensorListener);
    super.onStop();
  }
}

1 个答案:

答案 0 :(得分:1)

不要这样做

private Animation Animation, Animation2, Animation3, Animation4;

使用更好的名字,你确定你有18种不同的观点吗?

您还需要在ViewFlipper上设置动画,而不是布局