안드로이드에 윈도우 쌍 게임 (java로 작성)을 가져오고 있습니다. 하지만 이걸 실행하면 아무런 버튼도 볼 수 없습니다 ... (현재 내 코드는 제공하지 않습니다. 그것 빨리 uni)런타임에 안드로이드 뷰를 만드는 중
무엇이 여기에 잘못 될까요?
package mgh;
import mgh.mgh.R;
import android.app.Activity;
import android.content.Context;
import android.graphics.Color;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.AbsoluteLayout;
import android.widget.Button;
import android.widget.RelativeLayout;
public class mghActivity extends Activity implements OnClickListener {
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
new mghActivity();
}
public int numberOfClickes=0;
public card continueCard=null;
public int killedCards=0;
public card selectedCard=null;
public long spentTime=0;
public card[][] card=new card[4][4];
public void mghActivity(){
setTitle("pairs");
//setVisible(true);
//setSize(500,500);
//setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
AbsoluteLayout lay=new AbsoluteLayout(this);
int[] clr=new int[8];
short[] timesUsed=new short[8];
for (int i=0;i<=7;i++)
timesUsed[i]=0;
for (int i=0;i<=7;i++)
clr[i]= Color.rgb(((int)(Math.random()*2))*255,
((int)(Math.random()*2))*255,
((int)(Math.random()*2))*255);
for (int i=0;i<=3;i++)
for (int j=0;j<=3;j++){
int rnd=0;
while (timesUsed[rnd]>=2)
rnd=(int)(Math.random()*8)%8;
timesUsed[rnd]++;
card[i][j]=new card(this,clr[rnd]);
//card[i][j].setEnabled(false);
//AbsoluteLayout.LayoutParams mparams=new AbsoluteLayout.LayoutParams
//(lay.getWidth()/4,lay.getHeight()/4,(lay.getWidth()/4)*i,(lay.getWidth()/4)*j);
int m=40;
AbsoluteLayout.LayoutParams mparams=new AbsoluteLayout.LayoutParams
(m,m,m*i,m*j);
lay.addView(card[i][j],mparams);
card[i][j].setOnClickListener(this);
}
setContentView(lay);
}
public void onClick(View arg0) {
}
}
class card extends Button {///not completed
public int color;
public card(Context context,int color){
super(context);
this.color=color;
setBackgroundColor(color);
}
}
당신의 ['AbsoluteLayout'] (https://developer.android.com/reference/android/widget/AbsoluteLayout.html) - 더 이상 사용되지 않는 클래스입니다 _forever_, btw - 너비와 높이가 0이 될 때까지 화면에 배치. http://stackoverflow.com/questions/3591784/getwidth-and-getheight-of-view-returns-0 –
감사합니다. 감사합니다. –
아, 그래, 마크는 아래 답변에서도 좋은 점을 가지고 있습니다. 거기에'new' 키워드를 알지 못했습니다. 그건 그냥 작동하지 않습니다. 당신은 할 수없는'Activity'를 인스턴스화하려고 시도하지 않고, 메소드가 제대로 작동하도록해야합니다. –