Android 视图未显示在我的应用程序中

Android 视图未显示在我的应用程序中,android,canvas,view,Android,Canvas,View,我正在开发android abacus应用程序,因为我需要开发如下所示的用户界面,并且我正在使用以下逻辑。它编译和执行时没有异常,但视图不可见 所以,请指导我如何发展这个 **MainActivity** public class Hello extends Activity implements SensorListener { private MyView myView; private SensorManager sensorManager;

我正在开发android abacus应用程序,因为我需要开发如下所示的用户界面,并且我正在使用以下逻辑。它编译和执行时没有异常,但视图不可见

所以,请指导我如何发展这个

**MainActivity**



public class Hello extends Activity implements SensorListener
        {
      private MyView myView;
      private SensorManager sensorManager;

      public void onAccuracyChanged(int paramInt1, int paramInt2)
      {
      }

      public void onCreate(Bundle paramBundle)
      {
        super.onCreate(paramBundle);
        Log.e("hello", "hello");
        this.myView = new MyView(this);
        setContentView(this.myView);
        Log.e("hello", "hello after constructor");
        this.sensorManager = ((SensorManager)getSystemService("sensor"));
        this.myView.setTheme(2);
      }

      protected void onResume()
      {
        super.onResume();
        this.sensorManager.registerListener(this, 3, 0);
      }

      public void onSensorChanged(int paramInt, float[] paramArrayOfFloat)
      {
        switch (paramInt)
        {
        default:
        case 1:
        case 2:
        }
        this.myView.resetTama();
        do
        {
          do
            return;
          while (Math.abs(paramArrayOfFloat[2]) <= 50.0F);
        }
        while (Math.abs(paramArrayOfFloat[0]) <= 15.0F);

      }

      public void onWindowFocusChanged(boolean paramBoolean)
      {
        super.onWindowFocusChanged(paramBoolean);
        if (paramBoolean)
          this.myView.init();
      }
    }



 **MyView class**



public class MyView extends RelativeLayout
{
  private final int FP = -1;
  private final int WC = -2;
  public boolean disableApplication = false;
  private int imgType = 1;
  public boolean isBlack = false;
  boolean isInitialized;
  private Bitmap myBitmap;
  private Paint myPaint = new Paint();
  private int[] numbers;
  private Tama[] oyatamaArray;
  private Tama[][] tamaArray;

  public MyView(Context paramContext)
  {
    super(paramContext);
    Log.e("MyView", "MyView");
    setFocusable(true);
    setBackgroundResource(R.drawable.haikei);
    this.myBitmap = BitmapFactory.decodeResource(getContext().getResources(), R.drawable.tama);
    this.numbers = new int[6];

    //for displaying numbers

    for (int i = 0; i<numbers.length; i++)
    {
      if (i >= this.numbers.length)
      {
        loadChangeThemeButton(paramContext);
        new TextView(paramContext).setBackgroundResource(R.drawable.bar);
        return;
      }
      this.numbers[i] = 0;
    }
  }

  private void changeBackgroundImage()
  {
    int i = 1 + this.imgType;
    this.imgType = i;
    if (i > 3)
      this.imgType = 1;
    setTheme(this.imgType);
  }

  private void loadChangeThemeButton(Context paramContext)
  {
    ImageButton localImageButton = new ImageButton(paramContext);
    localImageButton.setBackgroundResource(R.drawable.themebutton);
    RelativeLayout.LayoutParams localLayoutParams = new RelativeLayout.LayoutParams(-2, -2);
    localLayoutParams.addRule(9);
    localLayoutParams.addRule(12);
    localLayoutParams.setMargins(0, 0, 30, 30);
    addView(localImageButton, localLayoutParams);
    localImageButton.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramView)
      {
        MyView.this.changeBackgroundImage();
      }
    });
  }
 private Bitmap returnNumberImg(Resources paramResources, int paramInt)
  {
    switch (paramInt)
    {
    default:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n0);
    case 1:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n1);
    case 2:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n2);
    case 3:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n3);
    case 4:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n4);
    case 5:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n5);
    case 6:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n6);
    case 7:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n7);
    case 8:
      return BitmapFactory.decodeResource(paramResources, R.drawable.n8);
    case 9:
    }
    return BitmapFactory.decodeResource(paramResources, R.drawable.n9);
  }

  private void settingTamasTouchX(int paramInt1, int paramInt2)
  {
    int i = 0;
    if (i >= this.oyatamaArray.length);
    int k;
    for (int j = 0; ; j++)
    {
      if (j >= this.tamaArray.length)
      {
        return;
      }
      k = 0;
      if (k < this.tamaArray[j].length)
      {
          if (this.tamaArray[j][k].checkArea(paramInt1, paramInt2));
            for (this.tamaArray[j][k].touchX = paramInt1; ; this.tamaArray[j][k].touchX = 0)
            {
              k++;
              break;
            }
//        break label90;
      }
    }
  }

  public void init()
  {
    int i = getHeight() / 7;
    int[] arrayOfInt = new int[6];
    int j = 5;
    //if (j < 0){
      this.oyatamaArray = new Tama[6];
    //}
    int m;
    int i1 = 0;
    for (int k = 0; ; k++)
    {
      if (k >= this.oyatamaArray.length)
      {
        this.tamaArray = ((Tama[][])Array.newInstance(Tama.class, new int[] { 6, 4 }));
        m = 0;
        if (m < this.tamaArray.length)
        {

            for (int n = 0; ; n++)
            {
              if (n >= this.tamaArray[m].length)
              {
                m++;
                break;
              }
              this.tamaArray[m][n] = new Tama(40 + n * 37, arrayOfInt[m] - 32, n + m * 10);
            }
//          break label154;
        }
        i1 = 0;
        if (i1 < this.tamaArray.length)
        {
            for (int i2 = 0; ; i2++)
            {
              if (i2 >= this.tamaArray[i1].length)
              {
                i1++;
                break;
              }
              if (i2 != this.tamaArray[i1].length - 1)
                this.tamaArray[i1][i2].ueTama = this.tamaArray[i1][(i2 + 1)];
              if (i2 == 0)
                continue;
              this.tamaArray[i1][i2].shitaTama = this.tamaArray[i1][(i2 - 1)];
            }
//          break label222;
        }
        this.isInitialized = true;
        return;
      }
      this.oyatamaArray[k] = new Tama(279, arrayOfInt[k] - 32, k);
      this.oyatamaArray[k].isOya = true;
    }
  }


  @Override
  protected void onDraw(Canvas paramCanvas)
  {


      Log.e("this is",".........onDraw");


    if (!this.isInitialized)
      init();
    int i = 0;
    Resources localResources;
    int m;
    while (true)
    {
      int j;
      if (i >= this.oyatamaArray.length)
      {
        j = 0;
        if (j >= this.tamaArray.length)
        {
          localResources = getContext().getResources();
          m = 0;
          if (m < 7)
            break;
          return;
        }
      }
      else
      {
        paramCanvas.drawBitmap(this.myBitmap, this.oyatamaArray[i].getX(), this.oyatamaArray[i].getY(), this.myPaint);
        i++;
        continue;
      }
      for (int k = 0; ; k++)
      {
        if (k >= this.tamaArray[j].length)
        {
          j++;
          break;
        }
        paramCanvas.drawBitmap(this.myBitmap, this.tamaArray[j][k].getX(), this.tamaArray[j][k].getY(), this.myPaint);
      }
    }
    if (this.numbers.length <= m)
    {
    for (Bitmap localBitmap = BitmapFactory.decodeResource(localResources, R.drawable.space); ; localBitmap = returnNumberImg(localResources, this.numbers[m]))
    {
      paramCanvas.drawBitmap(localBitmap, 8.0F, getHeight() / 2 + m * 18, this.myPaint);
      m++;
      break;
    }
    }
  }

  public boolean onTouchEvent(MotionEvent paramMotionEvent)
  {
    int i = (int)paramMotionEvent.getX();
    int j = (int)paramMotionEvent.getY();
    if ((paramMotionEvent.getAction() == 0) && (i >= 0) && (i <= 40) && (410 <= j) && (j <= 430))
      changeBackgroundImage();
    if (paramMotionEvent.getAction() == 0)
      settingTamasTouchX(i, j);
    if (1 == paramMotionEvent.getAction())
      settingTamasTouchX(0, 0);
    int k;
    int m = 0;
    if (2 == paramMotionEvent.getAction())
    {
      k = 0;
      if (k >= this.oyatamaArray.length)
      {
        m = 0;
        if (m < this.tamaArray.length)
        {
            for (int n = 0; ; n++)
            {
              if (n >= this.tamaArray[m].length)
              {
                m++;
                break;
              }
              this.tamaArray[m][n].checkAndSetArea(i, j);
              if (!this.tamaArray[m][n].isUp)
                continue;
              int[] arrayOfInt = this.numbers;
              arrayOfInt[m] = (1 + arrayOfInt[m]);
            }
//          break label164;
        }
        invalidate();
      }
    }
    else
    {
      return true;
    }
    this.oyatamaArray[k].checkAndSetArea(i, j);
    if (this.oyatamaArray[k].isUp)
      this.numbers[k] = 5;
    while (true)
    {
      k++;
      break;
    }
//    label164: 
    return disableApplication;
  }

  public void resetTama()
  {
    int j;
    for (int i = 0; ; i++)
    {
      if (i >= this.oyatamaArray.length)
      {
        j = 0;
        if (j < this.tamaArray.length)
          break;
        invalidate();
        return;
      }
      this.oyatamaArray[i].moveX(this.oyatamaArray[i].startX);
      this.oyatamaArray[i].isUp = false;
      this.numbers[i] = 0;
    }
    for (int k = 0; ; k++)
    {
      if (k >= this.tamaArray[j].length)
      {
        j++;
        break;
      }
      this.tamaArray[j][k].moveX(this.tamaArray[j][k].startX);
      this.tamaArray[j][k].isUp = false;
    }
  }

  public void sensorChange(float[] paramArrayOfFloat)
  {
    int i = 0;
    if (paramArrayOfFloat[2] < -50.0F)
      i = 0 - 3;
    int k;
    while (true)
    {
      int j = 0;
      if (j >= this.oyatamaArray.length)
      {
        k = 0;
        if (k < this.tamaArray.length)
          break;
        if (i != 0)
          invalidate();
        return;
      }
      else
      {
        this.oyatamaArray[j].moveX(i + this.oyatamaArray[j].getX());
        if (this.oyatamaArray[j].isUp)
          this.numbers[j] = 5;
        while (true)
        {
          j++;
          break;
        }
      }
    }
    for (int m = 0; ; m++)
    {
      if (m >= this.tamaArray[k].length)
      {
        k++;
        break;
      }
      this.tamaArray[k][m].moveX(i + this.tamaArray[k][m].getX());
      if (!this.tamaArray[k][m].isUp)
        continue;
      int[] arrayOfInt = this.numbers;
      arrayOfInt[k] = (1 + arrayOfInt[k]);
    }
  }

  public void setTheme(int paramInt)
  {
    Resources localResources = getContext().getResources();
    if (paramInt == 1)
    {
      this.myBitmap = BitmapFactory.decodeResource(localResources, R.drawable.tama);
      setBackgroundResource(R.drawable.haikei);
    }
    while (true)
    {
      invalidate();
//      return;
      if (paramInt == 2)
      {
        this.myBitmap = BitmapFactory.decodeResource(localResources, R.drawable.tama2);
        setBackgroundResource(R.drawable.haikei1);
        continue;
      }
      this.myBitmap = BitmapFactory.decodeResource(localResources, R.drawable.tama3);
      setBackgroundResource(R.drawable.haikei1);

    }
  }
}

**main活动**
公共类Hello扩展活动实现了SensorListener
{
私有MyView-MyView;
私人传感器管理器传感器管理器;
已更改准确性上的公共无效(int-paramInt1、int-paramInt2)
{
}
创建公共void(Bundle参数Bundle)
{
super.onCreate(paramBundle);
Log.e(“你好”、“你好”);
this.myView=新的myView(this);
setContentView(this.myView);
Log.e(“hello”,“构造函数之后的hello”);
this.sensorManager=((sensorManager)getSystemService(“传感器”);
this.myView.setTheme(2);
}
受保护的void onResume()
{
super.onResume();
this.sensorManager.registerListener(this,3,0);
}
已更改SensorChanged上的公共void(int paramInt,float[]paramaryOffLoat)
{
开关(参数)
{
违约:
案例1:
案例2:
}
this.myView.resetTama();
做
{
做
回来
while(Math.abs(paramArrayOfFloat[2])=this.oyatamarray.length);
int k;
对于(int j=0;j++)
{
如果(j>=this.tamaArray.length)
{
回来
}
k=0;
if(k=this.oyatamaray.length)
{
this.tamaArray=((Tama[][])Array.newInstance(Tama.class,newint[]{6,4}));
m=0;
if(m=this.tamaArray[m].length)
{
m++;
打破
}
this.tamaArray[m][n]=新的Tama(40+n*37,arrayOfInt[m]-32,n+m*10);
}
//折断标签154;
}
i1=0;
if(i1=this.tamaArray[i1].length)
{
i1++;
打破
}
if(i2!=this.tamaArray[i1].length-1)
this.tamaArray[i1][i2].ueTama=this.tamaArray[i1][(i2+1)];
如果(i2==0)
持续
this.tamaArray[i1][i2].shitaTama=this.tamaArray[i1][(i2-1)];
}
//打破标签222;
}
this.isInitialized=真;
回来
}
this.oyatamaArray[k]=新塔马(279,arrayOfInt[k]-32,k);
this.oyatamarray[k].isOya=true;
}
}
@凌驾
受保护的void onDraw(画布参数画布)
{
Log.e(“这是”、“……onDraw”);
如果(!this.i初始化)
init();
int i=0;
本地资源;
int m;
while(true)
{
int j;
如果(i>=this.oyatamaray.length)
{
j=0;
如果(j>=this.tamaArray.length)
{
localResources=getContext().getResources();
m=0;
如果(m<7)
打破
回来
}
}
其他的
{
paramCanvas.drawBitmap(this.myBitmap,this.oyatamarray[i].getX(),this.oyatamarray[i].getY(),this.myPaint);
i++;
持续
}
for(int k=0;k++)
{
如果(k>=this.tamaArray[j].length)
{
j++;
打破
}
paramCanvas.drawBitmap(this.myBitmap,this.tamaArray[j][k].getX(),this.tamaArray[j][k].getY(),this.myPaint);
}
}
如果(this.numbers.length=0)和&(i=this.oyatamarray.length)
{
j=0;
if(j=this.tamaArray[j].length)
{
j++;
打破
}
this.tamaArray[j][k].moveX(this.tamaArray[j][k].startX);
this.tamaArray[j][k].isUp=false;
}
}
公共空间传感器更改(浮动[]参数阵列浮动)
{
int i=0;
如果(paramArrayOfFloat[2]<-50.0F)
i=0-3;
int k;
while(true)
{
int j=0;
如果(j>=this.oyatamaray.length)
{
k=0;
if(k=this.tamaArray[k].length)
{
k++;
打破
}
this.tamaArray[k][m].moveX(i+this.tamaArray[k][m].getX();
如果(!this.tamaArray[k][m].isUp)
持续
int[]arrayOfInt=this.numbers;
arrayOfInt[k]=(1+arrayOfInt[k]);
}
}
公共void集合主题(int参数)
{
Resources localResources=getContext().getResources();
如果(参数==1)
{
this.myBitmap=BitmapFactory.decodeResource(localResources,R.drawable.t
this.myView = new MyView(this);
this.myView.setLayoutParams(new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));
this.addContentView(myView, new LayoutParams(LayoutParams.MATCH_PARENT,
                LayoutParams.MATCH_PARENT));