2010-09-03 122 views
5

我是Android开发的新手。现在我想像下面这样做圆形的图库视图。事情是,我想放大中心图像时,用户从左到右,从右到左滚动。有没有任何教程?android圆形画廊?

enter image description here 我想要的是被擦过的图像需要在放大的同时放大。我以为我可以用Gallery做到这一点。但是android开发者的例子并不是我想要的。 :(

回答

5


如果你想放大的中心选定的图像有一种可能的方式 在您onItemSelected方法,只需拨打一个动画放大的对象的属性画廊的是,它始终是中心锁定,所以中心元素将被永远选择。 希望将工作..

<?xml version="1.0" encoding="utf-8"?> 
<set 
    xmlns:android="http://schemas.android.com/apk/res/android" 
    android:shareInterpolator="false" 
    android:fillAfter="true" 
> 
<scale 
     android:fromXScale="1.0" 
     android:toXScale="1.50" 
     android:fromYScale="1.0" 
     android:toYScale="1.50" 
     android:duration="600" 
     android:pivotX="50%" 
     android:pivotY="50%" 
     android:fillAfter="true"/> 

</set> 

千万记住,你将不得不STO当元素从中心移开时,将前一个视图重新设置为正常大小。

所以你可以有两个视图 - prevView和currView。
在currView上做动画。

感谢,

12

遵守前面的尝试:。

public class TestGallery extends Activity { 
/** Called when the activity is first created. */ 
private Integer[] mImageIds = { R.drawable.sample_1, R.drawable.sample_2, R.drawable.sample_3, R.drawable.sample_4 }; 

@Override 
public void onCreate(Bundle savedInstanceState) { 
    super.onCreate(savedInstanceState); 
    setContentView(R.layout.main); 

    Gallery g = (Gallery) findViewById(R.id.gallery); 
    g.setAdapter(new ImageAdapter(this)); 

    g.setOnItemClickListener(new OnItemClickListener() { 
     public void onItemClick(AdapterView parent, View v, int position, long id) { 
      if (position >= mImageIds.length) { 
       position = position % mImageIds.length; 
      } 
      Toast.makeText(TestGallery.this, "" + position, Toast.LENGTH_SHORT).show(); 
     } 
    }); 

} 

public class ImageAdapter extends BaseAdapter { 
    int mGalleryItemBackground; 
    private Context mContext; 

    public ImageAdapter(Context c) { 
     mContext = c; 
     TypedArray a = obtainStyledAttributes(R.styleable.Gallery1); 
     mGalleryItemBackground = a.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 0); 

     a.recycle(); 
    } 

    public int getCount() { 
     return Integer.MAX_VALUE; 
    } 

    public Object getItem(int position) { 
     if (position >= mImageIds.length) { 
      position = position % mImageIds.length; 
     } 
     return position; 
    } 

    public long getItemId(int position) { 
     if (position >= mImageIds.length) { 
      position = position % mImageIds.length; 
     } 
     return position; 
    } 

    public View getView(int position, View convertView, ViewGroup parent) { 
     ImageView i = new ImageView(mContext); 
     if (position >= mImageIds.length) { 
      position = position % mImageIds.length; 
     } 
     i.setImageResource(mImageIds[position]); 
     i.setLayoutParams(new Gallery.LayoutParams(80, 80)); 
     i.setScaleType(ImageView.ScaleType.FIT_XY); 
     i.setBackgroundResource(mGalleryItemBackground); 
     return i; 
    } 

    public int checkPosition(int position) { 
     if (position >= mImageIds.length) { 
      position = position % mImageIds.length; 
     } 
     return position; 
    } 
}} 
+0

嗨pengwang列出我的教程来实现两者的这一点,我已经尝试过您的代码,它不会改变任何东西。有任何想法吗 ? – geekmyo 2010-09-06 05:33:40

+0

鹏旺的代码*通过扩展范围模拟*无限循环 – 2011-05-18 18:11:23

+0

+1感谢您的解决方案..! – 2012-01-13 09:36:22

1

我创建了自己本教程: http://evgeni-shafran.blogspot.com/2011/08/tutorial-custom-gallery-circular-and.html

因为这是圆的,你需要使它认为它有一个项目很多,多了很多,然后你真的有。

然后通过使位置=位置%items.length创建类似于(我将显示3项):1,2,3,1,2,3,1,2,3,1,2 ,3,1,2,3,1,2,3,1,2,3 然后去中间,所以即使滚动很多,他也不会靠近结尾。 1,2,3,1,2,3,1,2,3, - > < - ,2,3,1,2,3,1,2,3,1,2,3

要选择它:您需要重写setOnItemSelectedListener并处理大小。不要忘记保存对最后一个视图的引用,这样当你到达下一个视图时,可以使其看起来规则,而不是放大。

我在上面