|  | 
 
| 
该类声明的变量如下: 
 java代码: private int mGalleryWidth = 0;
 
 private boolean mIsTouched = false;
 
 private boolean mIsDragging = false;
 
 private float mCurrentOffset = 0.0f;
 
 private long mScrollTimestamp = 0;
 
 private int mFlingDirection = 0; 7
 
 private int mCurrentPosition = 0;
 
 private int mCurrentViewNumber = 0;
 
 private Context mContext;
 
 private Adapter mAdapter;
 
 private FlingGalleryView[] mViews;
 
 private FlingGalleryAnimation mAnimation;
 
 private GestureDetector mGestureDetector;
 
 private Interpolator mDecelerateInterpolater;
 其中主要变量有 mCurrentPosition:当前索引。
 mCurrentViewNumber:当前view的索引。
 mViews 用来存放一组滑动的view。
 mAnimation 动画动作。
 
 类中还封装了类似跳转到下一个view和上一个view的常用切换方法,以及一些常用的布局方法。
 
 在activity中可以这样使用:
 
 java代码: @Override
 
 public void onCreate(Bundle savedInstanceState) {
 
 super.onCreate(savedInstanceState);
 
 mGallery = new FlingGallery(this);
 
 //mGallery.setPaddingWidth(5);
 
 mGallery.setAdapter(mBabyListAdapter);
 
 mGallery.setIsGalleryCircular(true);
 
 LinearLayout layout = new LinearLayout(getApplicationContext());
 
 layout = (LinearLayout) PublicFunctionAndUnit.getMainView(
 
 GalleryTest.this, layout, mGallery);
 
 layout.setBackgroundResource(R.drawable.main_bg);
 
 setContentView(layout);
 
 }
 在adapter中把要显示的views放入其中,代码如下:
 
 java代码: BaseAdapter mBabyListAdapter = new BaseAdapter() {
 
 @Override
 
 public int getCount() {
 
 return 7; }
 
 @Override
 
 public Object getItem(int position) {
 
 return null;
 
 }
 
 @Override
 
 public long getItemId(int position) {
 
 return 0;
 
 }
 
 @Override
 
 public View getView(int position, View convertView, ViewGroup parent) {
 
 // GalleryViewItem item = new GalleryViewItem(GalleryTest.this,
 
 // position);
 
 LinearLayout item = getLinearLayout(GalleryTest.this, position);
 
 return item;
 
 }
 
 };
 
 private int[] itemViewIds = new int[] {
 
 R.layout.item1, R.layout.item2,
 
 R.layout.item3, R.layout.item4,
 
 R.layout.item5, R.layout.item6,
 
 R.layout.item7
 
 };
 
 private LinearLayout getLinearLayout(Context context, int position) {
 
 LinearLayout layout = new LinearLayout(context);
 
 LayoutInflater factory = LayoutInflater.from(context);
 
 View item = factory.inflate(itemViewIds[position], null);
 
 layout.addView(item, new LinearLayout.LayoutParams(
 
 LinearLayout.LayoutParams.FILL_PARENT,
 
 LinearLayout.LayoutParams.FILL_PARENT));
 
 return layout;
 
 }
 在使用过程中,发现该类,只有跳转到上一个和下一个view 的方法,不能指定跳转到某个view,仔细观察代码后,这个方法可以使用它所给的nextd等实现,代码如下:
 
 java代码:public void moveToViewbyId(int id)          {
 int num=id-mCurrentPosition;
 if(num!=0)
 {
 if(num>0)
 {
 for(int i=0;i<num;i++)
 {
 moveNext();
 }
 }
 else
 {
 for(int i=0;i<(0-num);i++)
 {
 movePrevious();
 }
 }
 }
 
 }
 | 
 |