2014-01-20 3 views
0

주위에 해결책을 찾을 수없는 이상한 행동이 있습니다 ... 내 스마트 폰 (Android 4.1)의 레벨 10 에뮬레이터 API 레벨 10에서만 정상적으로 작동합니다.Android : AnimationDrawable 내 이미지 집어 넣기

동적 인 애니메이션을 작성하여 애니메이션의 프레임으로 10 개의 임의 프레임이 선택되고 50ms의 지속 시간이 표시됩니다.

버튼을 누르면 애니메이션이 실행되지만 높이가 0으로 압착됩니다. (애니메이션 주사위에서 여전히 색상이 보일 수 있습니다.) 레이아웃도 엉망이됩니다. 내 휴대 전화에서는 이런 일이 발생하지 않습니다.

public void RollDice(View view) { 
    int id=-1; 
     AnimationDrawable diceAnimation = new AnimationDrawable(); 

     //create 10 random frames from dice1.jpg to dice6.jpg into diceAnimation 
     for(int j=0;j<10;j++){ 
      id=getResources().getIdentifier("dice"+String.valueOf(rng.nextInt(6)+1), "drawable", getPackageName()); 
      diceAnimation.addFrame(getResources().getDrawable(id), 50); 
     } 

     //assigning and starting animation 
     diceAnimation.setOneShot(true); 
     dice.setImageDrawable(diceAnimation); 
     diceAnimation.start(); 
} 

상기 XML 부분 : 여기서 During animation

Before animation

는 자바 코드의 부분 인

<ImageView 
android:id="@+id/Dice1" 
android:layout_width="match_parent" 
android:layout_height="wrap_content" 
android:contentDescription="@string/diceimage" 
android:src="@drawable/dice1" /> 

버튼은 온 클릭 RollDice()를 호출한다. 내가 이미지 뷰에 하드 코딩 경우

최종 발언으로, 안드로이드 말 : layout_height = "100dp"은 다음 주사위 애니메이션 동안 보여 주지만, 재미있는 모양으로 늘어나는 것과 것입니다 ...

During animation with 100dp

내가 시도 대부분의 스케일링 방법, 행운과 adjustviewbound 등 ...

+0

어떤 도움이 필요합니까? :( – Ivan

답변

0

나 자신이 초보자이기 때문에, 당신을 위해 답변을 할 수도 있습니다, 조심해 그것을 밖으로 시도하십시오. 내가 웹에서 다른 크기의 이미지을 많이 잡는거야 때 적용

ViewGroup.MarginLayoutParams mParams = new ViewGroup.MarginLayoutParams(view.getLayoutParams()); 

ImageView view = (ImageView)findViewById(R.id.image_dice); 
layoutParams = new RelativeLayout.LayoutParams(mParams); 
layoutParams.width=120; 
layoutParams.height=120; 
view.setLayoutParams(layoutParams); 

즉석에서 .XML를 조정합니다 이미지에,이어야 나를 위해 작동합니다.

1

귀하의 문제가 해결되었는지 여부를 모르겠습니다. 하지만이 질문에 대한 답변을 추가하고 싶습니다. , 첫째

를 wrap_content하는 match_parent에서 당신에게 이미지보기 layout_width을 설정

이 작업을 시도 할 수 있습니다. 주사위 완전히 사라지게되도록 코드 아래의이

메이크

제 이용 :

frameAnimation.setVisibility (GONE);

관련 문제