2017-01-19 1 views
0

그래서 1은 2 ImageButtons, clothesButton1, xml로 선언 된 이미지, 그리고 imageButton2은 비어 있습니다. 둘 다 별도의 활동에 있습니다. clothesButton1을 클릭하면 비트 맵을 사용하여 clothesButton1의 이미지를 imageButton2으로 옮기고 싶습니다. 이후에 clothesButton1이 비어있게됩니다. (imageButton2에 대한) 내 두 번째 활동에서별도의 액티비티에있는 ImageButton 간의 이미지 이동 onClick 비트 맵

final ImageButton clothesButton1 =(ImageButton)findViewById(R.id.clothesBtn1); 

clothesButton1.setOnClickListener(new View.OnClickListener() { 
     public void onClick(View v) { 

      clothesButton1.buildDrawingCache(); 
      Bitmap bitmapclothes = clothesButton1.getDrawingCache(); 
      Intent intent = new Intent(); 
      intent.putExtra("BitmapClothes", bitmapclothes); 
     } 
    }); 

:

여기 clothesButton1 자바에서 내 코드의

final ImageButton imageButton2 = (ImageButton)findViewById(R.id.imageButton2); 
Intent intent = getIntent(); 
Bitmap bitmap = (Bitmap) intent.getParcelableExtra("BitmapClothes"); 
imageButton2.setImageBitmap(bitmap); 

이동 기능이 작동되지 않고, 난 정말 아무 생각이 곳이 없다 그러나 나는 틀렸다. 어떤 도움이라도 대단히 감사합니다.

답변

0

오류 때문에 의도이다. 안드로이드의 명시 적 의도와 암시 적 의도에는 두 가지 유형의 의도가 있습니다. 컨텍스트와 클래스 객체로 인 텐트를 생성하면 명시적인 인 텐트가 생성됩니다. 명시 적 인 텐트를 사용하여 응용 프로그램 내에서 활동을 시작합니다. 응용 프로그램의 활동이 다른 응용 프로그램에서 활동을 시작하려면 암시 ​​적 인 텐트를 작성합니다. 귀하의 경우 명시 적 의도는 의도 의도 = 새로운 의도 (getApplicationContext(), secondActivityName.class)입니다.

Intent intent=new Intent(getApplicationContext(),secondActivityName.class); 
intent.putExtra("BitmapClothes", bitmapclothes); 
startActivity(intent); 

귀하의 경우에는 의도 read this tutorial에 대한 자세한 내용을 이해합니다.

+0

설명과 도움에 감사드립니다. 그러나, 나는 getContext()를 사용하여 시도했지만 "메서드를 해결할 수 없습니다". 그래서 대신 작동하도록 getApplicationContext()를 사용했습니다. 다행히도 앱에 많은 차이가 있음을 의미하지는 않습니다. – xlayer

+0

예, 귀하의 오른쪽 기쁘게 도와 드리겠습니다! – Yirga

0

먼저 getDrawingCache()이 null을 반환하고 둘째로 다른 활동을 호출하는 방식이 올바르지 않습니다! 이 시도 :

clothesButton1.setDrawingCacheEnabled(true); 
clothesButton1.measure(View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED), 
        View.MeasureSpec.makeMeasureSpec(0, View.MeasureSpec.UNSPECIFIED)); 
clothesButton1.layout(0, 0, clothesButton1.getMeasuredWidth(), imageButton.getMeasuredHeight()); 
clothesButton1.buildDrawingCache(true); 
Bitmap bitmapclothes = Bitmap.createBitmap(clothesButton1.getDrawingCache()); 
clothesButton1.setDrawingCacheEnabled(false); 
Intent intent = new Intent(NowActivity.this,SecondActivity.class); 
intent.putExtra("BitmapClothes", bitmapclothes); 
startActivity(intent); 

참조 : Android View.getDrawingCache returns null, only null

+0

설명과 상세한 코드를 가져 주셔서 감사합니다! DrawingCache에 대한 새로운 것을 확실히 배웠습니다. 귀하의 코드는 저에게 효과적이지만 새로운 솔루션보다 약간 오래갑니다. 다른 사람들이 나중에 다른 사람들이 사용할 필요가있는 경우에 upvote 할 것입니다. – xlayer

+0

이것은 DrawingCache를 사용하는 가장 좋은 방법입니다. 참고 자료의 두 번째 솔루션처럼 캔버스에 직접 그려 볼 수도 있습니다. –

0

당신이 Activity Transition으로 쉽게 달성 할 수 있다고 생각합니다. 그것을 잘 보아라 :) Start an activity with a shared element 섹션이 당신이 원하는 것일 수도있다.