在Android中缩放画廊的中心图像

时间:2012-01-30 15:30:50

标签: android gallery zoom

请指导我...我希望画廊的中心图像放大。我怎么能这样做。

enter image description here

2 个答案:

答案 0 :(得分:0)

这需要一些工作。使用相对布局,将图像设置为layout_width = fill_parent,layout_height = fill_parent(根据需要设置图像比例),并将图库部分与屏幕底部对齐。然后使用自定义主题自定义图库以使其透明。

答案 1 :(得分:0)

<强> main.xml中

<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout 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/ImageView01" 
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"></ImageView>
    <Gallery 
    android:id="@+id/Gallery01" 
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content"
    android:layout_alignParentBottom="true"

    ></Gallery>
</RelativeLayout>

<强>活动

    public class GalleryView extends Activity {
        Integer[] pics = {
                R.drawable.antartica1,
                R.drawable.antartica2,
                R.drawable.antartica3,
                R.drawable.antartica4,
                R.drawable.antartica5,
                R.drawable.antartica6,
                R.drawable.antartica7,
                R.drawable.antartica8,
                R.drawable.antartica9,
                R.drawable.antartica10
        };
        ImageView imageView;
       // int i=0,j,k;

        /** Called when the activity is first created. */
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.main);

            Gallery ga = (Gallery)findViewById(R.id.Gallery01);
            ga.setAdapter(new ImageAdapter(this));

            imageView = (ImageView)findViewById(R.id.ImageView01);
            /*i=ga.getSelectedItemPosition();
            j=ga.getFirstVisiblePosition();
            k=ga.getLastVisiblePosition();*/

            ga.setOnItemSelectedListener(new OnItemSelectedListener() {


                @Override
                public void onItemSelected(AdapterView<?> arg0, View arg1,
                        int arg2, long arg3) {
                    // TODO Auto-generated method stub
                     imageView.setBackgroundResource(pics[arg2]);

                }

                @Override
                public void onNothingSelected(AdapterView<?> arg0) {
                    // TODO Auto-generated method stub
                }
            });


            ga.setOnItemClickListener(new OnItemClickListener() {

                @Override
                public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
                        long arg3) {
                    Toast.makeText(getBaseContext(), 
                            "You have selected picture " + (arg2+1) + " of Antartica", 
                            Toast.LENGTH_SHORT).show();
                    //imageView.setImageResource(pics[arg2]);
                    imageView.setBackgroundResource(pics[arg2]);


                }

            });

        }


        public class ImageAdapter extends BaseAdapter {

            private Context ctx;
            int imageBackground;

            public ImageAdapter(Context c) {
                ctx = c;
                TypedArray ta = obtainStyledAttributes(R.styleable.Gallery1);
                imageBackground = ta.getResourceId(R.styleable.Gallery1_android_galleryItemBackground, 1);
                ta.recycle();
            }
        @Override
        public int getCount() {

            return pics.length;
        }

        @Override
        public Object getItem(int arg0) {

            return arg0;
        }

        @Override
        public long getItemId(int arg0) {

            return arg0;
        }

        @Override
        public View getView(int arg0, View arg1, ViewGroup arg2) {
            ImageView iv = new ImageView(ctx);
            iv.setImageResource(pics[arg0]);
            iv.setScaleType(ImageView.ScaleType.FIT_XY);
            iv.setLayoutParams(new Gallery.LayoutParams(150,120));
            iv.setBackgroundResource(imageBackground);
            return iv;
        }

    }
}