2016-03-30 56 views
1

我正在開發tinder刷卡庫。所以我將這個參考文獻引用爲Sample在刷卡中獲取滑動圖像位置[Tinder Swipe]

我的問題是,在滑動圖像時,我需要獲取滑動的圖像位置。到目前爲止,我嘗試了像int idGet = flingContainer.getSelectedItemPosition();但它不適用於我。

下面我已經發布相關代碼:

的logcat:

E:/ idGet : -1 

CardsFragment.java:

public class CardsFragment extends Fragment { 

private SwipeFlingAdapterView flingContainer; 

@Override 
    public View onCreateView(LayoutInflater inflater, ViewGroup container, 
          Bundle savedInstanceState) { 

    flingContainer = (SwipeFlingAdapterView) rootView.findViewById(R.id.frame); 


     likeImg.setOnClickListener(new View.OnClickListener() { 
      @Override 
      public void onClick(View view) { 

       likeNope(); 
       flipMethodRight(80.00f); 

      } 
     }); 

     } 
    } 

    void flipMethodRight(float scrollProgressPercent) { 


     flingContainer.getTopCardListener().selectRight(); 

     View view = flingContainer.getSelectedView(); 


     view.findViewById(R.id.background).setAlpha(0); 

     view.findViewById(R.id.item_swipe_left_indicator).setAlpha(scrollProgressPercent > 0 ? scrollProgressPercent : 0); 

    } 

    public class MyAppAdapter extends BaseAdapter { 

     public List<GetImageData> parkingList; 
     public Context context; 

     private MyAppAdapter(List<GetImageData> apps, Context context) { 
      this.parkingList = apps; 
      this.context = context; 
     } 

     @Override 
     public int getCount() { 
      return parkingList.size(); 
     } 

     @Override 
     public Object getItem(int position) { 
      return position; 
     } 

     @Override 
     public long getItemId(int position) { 
      return position; 
     } 

     @Override 
     public View getView(final int position, View convertView, ViewGroup parent) { 

      View rowView = convertView; 

      if (rowView == null) { 

       LayoutInflater inflater =getActivity(). getLayoutInflater(); 
       rowView = inflater.inflate(R.layout.adapt_card_frag, parent, false); 

       Log.e("AdapterCalling", "AdapterCalling"); 

       // configure view holder 
       viewHolder = new ViewHolder(); 
       viewHolder.DataText = (TextView) rowView.findViewById(R.id.bookText); 
       viewHolder.background = (FrameLayout) rowView.findViewById(R.id.background); 
       viewHolder.cardImage = (ImageView) rowView.findViewById(R.id.cardImage); 

       Log.e("ParkingList", "" +parkingList.get(position).getDescription() + ""); 

       int idGet = flingContainer.getSelectedItemPosition(); 

       Log.e("idGet", ""+idGet); 


       rowView.setTag(viewHolder); 

      } else { 
       viewHolder = (ViewHolder) convertView.getTag(); 
      } 




      viewHolder.DataText.setText(parkingList.get(position).getDescription() + ""); 



      Glide.with(CardsFragment.this).load(parkingList.get(position).getImagePath()).into(viewHolder.cardImage); 

      return rowView; 
     } 
    } 

回答

0

我解決了這個問題,用下面的代碼的幫助:

String getImageFlingStr, GET_PRESENT_IMAGE; 


getImageFlingStr = nameImgArrList.get(0).getImagePath(); 

presentImageShowing = getImageFlingStr; 

GET_PRESENT_IMAGE = presentImageShowing; 

Log.e("presentImageShowing", ""+presentImageShowing);