Gallery拖动效果的使用:
- <?xml version="1.0" encoding="utf-8"?>
- <Gallery xmlns:android="http://schemas.android.com/apk/res/android"
- android:id="@+id/Gallery"
- android:layout_width="fill_parent"
- android:layout_height="wrap_content">
- </Gallery>
- package com.Aina.Android;
-
- import android.content.Context;
- import android.util.Log;
- import android.view.View;
- import android.view.ViewGroup;
- import android.widget.BaseAdapter;
- import android.widget.Gallery;
- import android.widget.ImageView;
-
- public class ImageAdapter extends BaseAdapter {
-
- private Context mContext;
- private Integer[] mImageIds = {
- R.drawable.img1,
- R.drawable.img2,
- R.drawable.img3,
- R.drawable.img4,
- R.drawable.img5,
- R.drawable.img6,
- R.drawable.img7,
- R.drawable.img8
- };
- public ImageAdapter(Context c){
- this.mContext = c;
- }
- @Override
- public int getCount() {
- return mImageIds.length;
- }
-
- @Override
- public Object getItem(int position) {
- return position;
- }
-
- @Override
- public long getItemId(int position) {
- return position;
- }
-
- @Override
- public View getView(int position, View convertView, ViewGroup parent) {
- Log.i("TAG", position+"");
- ImageView imageView = new ImageView(mContext);
- imageView.setImageResource(mImageIds[position]);
- imageView.setLayoutParams(new Gallery.LayoutParams(100,100));
- imageView.setScaleType(ImageView.ScaleType.FIT_CENTER);
- return imageView;
- }
-
- }
- package com.Aina.Android;
-
- import android.app.Activity;
- import android.os.Bundle;
- import android.view.View;
- import android.widget.AdapterView;
- import android.widget.Gallery;
- import android.widget.Toast;
- import android.widget.AdapterView.OnItemClickListener;
-
- public class Test_Gallery extends Activity {
-
- @Override
- public void onCreate(Bundle savedInstanceState) {
- super.onCreate(savedInstanceState);
- setContentView(R.layout.main);
- Gallery g = (Gallery) this.findViewById(R.id.Gallery);
- g.setAdapter(new ImageAdapter(this));
- g.setBackgroundResource(R.drawable.bg0);
- g.setOnItemClickListener(new OnItemClickListener(){
-
- @Override
- public void onItemClick(AdapterView<?> arg0, View arg1, int arg2,
- long arg3) {
- Toast.makeText(Test_Gallery.this, "选择了"+(arg2+1)+"号图片", Toast.LENGTH_SHORT).show();
- }
-
- });
- }
- }
分享到:
相关推荐
android----gallery、iamgeswitcher组件详解,及简单实例。
android gallery简单应用,里面有对gallery源码例子
android开发中,Gallery控件的使用,详细可以参见博客:http://www.cnblogs.com/plokmju/p/android_Gallery.html
android gallery例子android gallery例子android gallery例子
android gallery demoandroid gallery demoandroid gallery demo
Android Gallery 自定义ImageView和Gallery实现图片浏览功能,类似Android图库软件,主要实现的功能有:图片左右滑动、放大缩小、放大弹回、缩小弹回。 一开始使用Viewpager实现图片浏览,发现两张图片滑动时没有...
android Gallery + ImageSwitcher
自己写的一个Android Gallery 小例子,共享给大家顺便自己保存一下。
Android Gallery 3D效果 非常好的伪3D效果...
Android Gallery画廊 图片展示控件 博客地址:http://blog.csdn.net/csdnyuandaimaxuexi/article/details/48809349
Android Gallery 特效
使用gallery实现图片滑动的同时 还实现了被选中的图片放大
Android Gallery 左对齐,点击禁止滑动 demo
android 4.0 Gallery源码
android gallery3d效果的简单实现 有遮盖 http://blog.csdn.net/kiritor/article/details/8701025
Android 重写Gallery实现gallery的动画切换效果
Android Gallery控件使用实例
Android应用源码之Gallery2_Android
android Gallery(画廊)以及BaseAdapter
Android自定义Gallery 自定义边框 底部小圆点 自动切换