2014-12-22 4 views
0

이미지 캡처 단편을 가지고 있으며 찍은 모든 그림을 동일한 단편에 ViewPager 갤러리로 표시하려고합니다.ViewPager 이미지 갤러리에 조각이 보이지 않음 - 안드로이드

흐름 : 사용자가 이미지 찍기 버튼을 클릭하고 인 텐트가 카메라를 열면 사진을 찍고 onActivityResult가 내 미리보기 이미지 메서드를 호출하여 모든 사진과 함께 ViewPager를 볼 수 있도록해야합니다.

사진을 bitmaps라는 전역 ArrayList에 보관합니다.

global: 
ArrayList<Bitmap> bitmaps = new ArrayList<Bitmap>(); 
ImagePagerAdapter adapter = new ImagePagerAdapter(); 

public View onCreateView(LayoutInflater inflater, ViewGroup container, 
         Bundle savedInstanceState) { 
..... 
viewPager = (ViewPager) view.findViewById(R.id.view_pager);} 

내 previewCapturedImage 방법 :

내 PagerAdapter가 :

private class ImagePagerAdapter extends PagerAdapter { 

    @Override 
    public int getCount() { 
     return bitmaps.size(); 
    } 
    @Override 
    public boolean isViewFromObject(View view, Object object) { 
     return view == ((ImageView) object); 
    } 
    @Override 
    public Object instantiateItem(ViewGroup container, int position) { 
     ImageView imageView = new ImageView(context); 
     int padding = 15; 
     imageView.setPadding(padding, padding, padding, padding); 
     imageView.setScaleType(ImageView.ScaleType.CENTER_INSIDE); 
     imageView.setImageBitmap(bitmaps.get(position)); 
     ((ViewPager) container).addView(imageView, 0); 
     return imageView; 
    } 
    @Override 
    public void destroyItem(ViewGroup container, int position, Object object) { 
     ((ViewPager) container).removeView((ImageView) object); 
    } 
} 

내 XML :

previewCapturedImage의 끝에서
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" 
android:layout_width="match_parent" 
android:layout_height="match_parent" 
android:background="#ffffff" 
android:orientation="vertical"> 
.... 

<ScrollView xmlns:android="http://schemas.android.com/apk/res/android" 
    android:id="@+id/scrollView" 
    android:layout_width="wrap_content" 
    android:layout_height="fill_parent" 
    android:layout_below="@+id/titlu2" 
    android:layout_marginBottom="60dp" 
    android:background="#ffffff" 
    android:orientation="vertical"> 


    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" 
     android:id="@+id/butoane_foto" 
     android:layout_width="fill_parent" 
     android:layout_height="fill_parent" 
     android:layout_marginLeft="5dp" 
     android:layout_marginRight="5dp" 
     android:layout_marginTop="5dp" 
     android:orientation="vertical"> 
     ..... 

     <LinearLayout 
      android:layout_width="fill_parent" 
      android:layout_height="fill_parent" 
      android:orientation="vertical" 
      android:padding="10dp"> 

      <!-- To display picture taken --> 

      <android.support.v4.view.ViewPager 
       xmlns:android="http://schemas.android.com/apk/res/android" 
       android:id="@+id/view_pager" 
       android:layout_width="match_parent" 
       android:layout_height="match_parent"/> 
       <!--android:visibility="gone"--> 


     </LinearLayout> 

     ..... 
    </LinearLayout> 
</ScrollView> 

    ........... 
</RelativeLayout> 

답변

0

이 줄을 추가가 통지하는 어댑터 데이터가 변경 되었음 :

adapter.notifyDataSetChanged(); 
+1

여전히 작동하지 않습니다. – Juvie22

관련 문제