마스터Q&A 안드로이드는 안드로이드 개발자들의 질문과 답변을 위한 지식 커뮤니티 사이트입니다. 안드로이드펍에서 운영하고 있습니다. [사용법, 운영진]

랜덤값을 받아 이미지 이동시킬때요 어떻게하나요?

0 추천

학교에서 공부중에 있는데 원낙 얇고 넓게 배우는터라 막히네요 ... 부루마블을 만들려고 생각하는데 주사위 굴리는는 해결됬는데 이동을 못시겠어요 ... 트윈애니매이션 말고 다른거 있음 말씀좀 해주세요 부탁드리겠습니다 ㅠㅠ 

 

public class Pan_Activity extends Activity implements OnClickListener{
    Button btn_dice;
    ImageView player;
    LinearLayout dicepan;
    AnimationDrawable mAni;
int nR; 
TranslateAnimation Tans;
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Window win = getWindow();  
   win.requestFeature(Window.FEATURE_NO_TITLE);  
   win.addFlags(WindowManager.LayoutParams.FLAG_FULLSCREEN); 
setContentView(R.layout.pan);
btn_dice = (Button)findViewById(R.id.btn_dice);
player = (ImageView)findViewById(R.id.image_play);
dicepan = (LinearLayout)findViewById(R.id.LinearLayout1);
   final ImageView dice1 = (ImageView)findViewById(R.id.dice1);
ImageView dice2 = (ImageView)findViewById(R.id.dice2);

setImage(dice1);
setImage(dice2);

nR = new Random().nextInt(11)+1;

btn_dice.setOnClickListener(this);
}
public void setImage(ImageView dice)
{

if(nR == 0)
dice.setImageResource(R.drawable.d1);
else if(nR == 1)
dice.setImageResource(R.drawable.d2);
else if(nR == 2)
dice.setImageResource(R.drawable.d3);
else if(nR == 3)
dice.setImageResource(R.drawable.d4);
else if(nR == 4)
dice.setImageResource(R.drawable.d5);
else if(nR == 5)
dice.setImageResource(R.drawable.d6);
}


@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
Animation anim = null;
switch (arg0.getId()) {
case R.id.btn_dice:
if(nR == 2){
anim = new TranslateAnimation(0, -200, 0, 0);
}else if (nR == 3) {
anim = new TranslateAnimation(0, -300, 0, 0);
}else if (nR == 4) {
anim = new TranslateAnimation(0, -400, 0, 0);
}else if (nR == 5) {
anim = new TranslateAnimation(0, -500, 0, 0);
}else if (nR == 6) {
anim = new TranslateAnimation(0, -600, 0, 0);
}else if (nR == 7) {
anim = new TranslateAnimation(0, -700, 0, 0);
}else if (nR == 8) {
anim = new TranslateAnimation(0, -800, 0, 0);
}else if (nR == 9) {
anim = new TranslateAnimation(0, -900, 0, 0);
}else if (nR == 10) {
anim = new TranslateAnimation(0, -1000, 0, 0);
}else if (nR == 11) {
anim = new TranslateAnimation(0, -1100, 0, 0);
}else if (nR == 12) {
anim = new TranslateAnimation(0, -1200, 0, 0);
}
break;
}
  anim.setFillAfter(true);
      anim.setDuration(1000);
  player.startAnimation(anim);
}
}

 

 

마린블루쓰 (200 포인트) 님이 2013년 5월 3일 질문
아래 코드가 잘못되었네요...

anim = new TranslateAnimation(0, -100*nR, 0, 0);
로 작성하세요
감사합니다 ㅎㅎ //그러나 여전히 위치가 바뀌지는 않는군요 .ㅠㅠ
헛 그림이 랜덤으로 움직입니다 감사합니다 ㅎㅎ

답변 달기

· 글에 소스 코드 보기 좋게 넣는 법
· 질문에 대해 추가적인 질문이나 의견이 있으면 답변이 아니라 댓글로 달아주시기 바랍니다.
표시할 이름 (옵션):
개인정보: 당신의 이메일은 이 알림을 보내는데만 사용됩니다.
스팸 차단 검사:
스팸 검사를 다시 받지 않으려면 로그인하거나 혹은 가입 하세요.
...