2010-09-03 121 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並處理大小。不要忘記保存對最後一個視圖的引用,這樣當你到達下一個視圖時,可以使其看起來規則,而不是放大。

我在上面