从侧面的android图像幻灯片

时间:2011-12-17 00:47:34

标签: android image gallery

我已经实现了一个图库,触摸屏幕中央显示图像

现在图像刚刚弹出。如何获得屏幕左侧或右侧的图像效果,滑动效果

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical" android:layout_width="fill_parent"
    android:layout_height="fill_parent" >

        <ImageView android:id="@+id/imageView1" android:layout_width="200dip"
        android:layout_height="200dip" ></ImageView>
    <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/gallery" android:layout_width="fill_parent"
        android:layout_height="wrap_content" 
        android:layout_marginLeft="0dip" android:paddingLeft="0dip"/>
    </LinearLayout>

适配器代码:

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

    ImageView imageView = new ImageView(mContext);

    imageView.setImageResource(mImageIds[position]);
    imageView.setLayoutParams(new Gallery.LayoutParams(100, 100));
    imageView.setScaleType(ImageView.ScaleType.FIT_XY);
    imageView.setBackgroundResource(mGalleryItemBackground);

    return imageView;
}

图库活动:

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

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

    gallery.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position, long id) {
            ImageView image = (ImageView) 
                    findViewById(R.id.imageView1);

            image.setImageResource(mImageIds[position]);

        }
    });
}

1 个答案:

答案 0 :(得分:1)

这是我找到的解决方案

listview.setOnItemClickListener(new OnItemClickListener() {
        public void onItemClick(AdapterView parent, View v, int position,
                long id) {
            ImageView image = (ImageView) findViewById(R.id.imageView1);
            Animation exitAnimation;

            if(position<positionLastCLicked){
             exitAnimation = AnimationUtils.loadAnimation(
                    GalleryActivity.this, R.layout.image_slidefromleft);}
            else{
                 exitAnimation = AnimationUtils.loadAnimation(
                        GalleryActivity.this, R.layout.image_slidefromright);
            }
            positionLastCLicked = position;
            image.startAnimation(exitAnimation);
            Utils.imageLoader.DisplayImage(galleryList.get(position)
                    .getImage(), image);
        }

slidefromleft.xml

    <?xml version="1.0" encoding="utf-8"?>
<translate
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:toXDelta="0%"
    android:fromXDelta="-100%"
    android:duration="400" 
    android:fillEnabled="true" 
    android:fillAfter="true">
</translate>