2014-04-17 3 views
1

각 목록 항목에 textviews와 viewpager가있는 listview가 있습니다. 나는 Airbnb 앱과 마찬가지로 viewpager를 통해 각 listitem에서 스크롤 가능한 이미지를 원한다.목록보기 행 내 Viewpage

구현하려고했지만 문제는 목록 어댑터에서 새 viewpager 인스턴스를 만들고 viewpager에 새 ID를 설정해야한다는 것입니다. 또한 새로운 FragmentStatePagerAdapter를 만들고 viewpager에 설정할 때마다. 뷰 페이지 및 어댑터 재사용시 앱이 다운됩니다.

그래서 listview에서 뷰 페이지를 통합 할 수있는 방법이나 라이브러리가 있습니까 ??

여기 내 코드 SimpleCursorAdapter를 listview에 사용하고 SimpleCursorAdapter.ViewBinder를 사용하여 뷰 페이지 어댑터를 바인딩합니다.

SimpleCursorAdapter.ViewBinder

... 

    enter code here 
    listPager = new ViewPager(MainListActivity.this); 
    listPager.setId(R.id.viewpager_id_base + cursor.getPosition() + 1); 
    listPager.setPageMargin(-(int) (pageMargin * 1.5)); 
    listPager.setLayoutParams(pagerParams); 

    imageList  = MainListDAO.getMedia(rowId); 
    mediaAdapter = new ViewPagerAdapter(getSupportFragmentManager(), imageList); 
    mediaAdapter . setCount(imageList.size()); 
    listPager.setAdapter(mediaAdapter); 

... 


listitem.xml 
... 
    <LinearLayout 
       android:layout_width="wrap_content" 
       android:layout_height="wrap_content" 
       android:layout_marginLeft="5dp" 
       android:gravity="center_horizontal" 
       android:orientation="vertical" 
       android:paddingTop="5dp" > 

       <TextView 
        android:id="@+id/txtCommentCount" 
        style="@style/textStyle" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" /> 

       <ImageView 
        android:id="@+id/txtSending" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:padding="5dp" 
        android:src="@drawable/clock" /> 

       <ImageView 
        android:id="@+id/imgMute" 
        android:layout_width="wrap_content" 
        android:layout_height="wrap_content" 
        android:layout_gravity="right" 
        android:padding="5dp" 
        android:src="@drawable/ic__mute_small" /> 
      </LinearLayout> 
     </LinearLayout> 

     <LinearLayout 
      android:id="@+id/lytMedia" 
      android:layout_width="match_parent" 
      android:layout_height="wrap_content" 
      android:orientation="vertical" > 


      <android.support.v4.view.ViewPager 
       android:id="@+id/viewPager" 
       android:layout_width="fill_parent" 
       android:layout_height="wrap_content" 
       android:layout_marginTop="@dimen/activity_default_margin" 
       android:focusable="false" 
       android:focusableInTouchMode="true" > 
      </android.support.v4.view.ViewPager> 


     </LinearLayout> 

...

+0

이미 시도한 코드를 게시하면 도움이 될 것입니다. – Blacklight

+0

[도움이 될 수도 있습니다] (http://dallasgutauckis.com/2013/04/30/android-putting-a-viewpager-inside-a-listview/) * - thanks Google. * [this one] (http : //stackoverflow.com/questions/14920459/placing-viewpager-as-a-row-in-listview), [another one] (http://stackoverflow.com/questions/21334599/android-listview-with-swipe- 내부 - 뷰 페이지) 및 [그 하나] (http://stackoverflow.com/questions/17173545/multiple-viewpages-inside-single-listview-is-crashing) * - 감사합니다. * – Fllo

+0

왜 새로운 ID가 뷰 페이지에 있습니까? 필요한 경우 어댑터를 다시 작성해야하지만 가능한 경우 데이터 세트를 변경할 수는 있습니다. 하지만 확실히 뷰 페이지를 재사용 할 수 있습니다. – rekaszeru

답변

0

내가 같은를 구현하려고 않았다,하지만 성공.

앱이 맞춤 구성 요소를 구현한다고 생각합니다. 예 : Moto G, Samsung Galaxy Note II와 같은 모든 장치에서 작동하지 않습니다. 항목이 목록처럼 표시되고 가로 호출기가 비활성화됩니다.

AndroidImageSlider 라이브러리를 사용하여 Recyclerview의 각 항목을 구현할 수 있습니다. 이 메서드에서는 onBindViewHolder을 구현하고 SliderLayout 특성을 설정하는 사용자 지정 어댑터를 만들어야합니다. 나는 해냈고 ...