文档详情

安卓图片切换源代码+注释

橙**
实名认证
店铺
PDF
558.23KB
约6页
文档ID:333367379
安卓图片切换源代码+注释_第1页
1/6

效果图代码Ativity 代码package com.android.lrw;import android.app.Activity;import android.content.Context;import android.os.Bundle;名师资料总结-精品资料欢迎下载-名师精心整理-第 1 页,共 6 页 -import android.v iew.View;import android.v iew.ViewGroup;import android.v iew.Window;import android.v iew.animation.AnimationUtils;import android.widget.AdapterView;import android.widget.BaseAdapter;import android.widget.Button;import android.widget.CheckBox;import android.widget.EditT ext;import android.widget.Gallery;import android.widget.ImageSwitcher;import android.widget.ImageView;import android.widget.T extView;import android.widget.ViewSwitcher;import android.widget.Gallery.LayoutParams;public class ImgShowActivity extends Activity implements AdapterView.OnItemSelectedListener,ViewSwitcher.ViewFactory Override public void onCreate(Bundle savedInstanceState)super.onCreate(savedInstanceState);requestWindowFeature(Window.FEATURE_NO_TITLE);setContentView(R.layout.imageshow);setTitle(ImageShowActivity);mSwitcher=(ImageSwitcher)findViewById(R.id.Switcher);mSwitcher.setFactory(this);mSwitcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in);mSwitcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out);Gallery g=(Gallery)findViewById(R.id.Gallery);g.setAdapter(new ImageAdapter(this);g.setOnItemSelectedListener(this);/*当图片被选择时的方法*/public void onItemSelected(AdapterView parent,View v,int position,long id)mSwitcher.setImageResource(mImageIdsposition);/*当图片未被选择时的方法*/public void onNothingSelected(AdapterView parent)/*名师资料总结-精品资料欢迎下载-名师精心整理-第 2 页,共 6 页 -*ImageSwitcher 的使用方法*/public View makeView()ImageView i=new ImageView(this);i.setBackgroundColor(0 xFF000000);i.setScaleTy pe(ImageView.ScaleType.FIT_CENTER);i.setLayoutParams(new ImageSwitcher.LayoutParams(LayoutParams.FILL_PARENT,LayoutParams.FILL_PARENT);return i;private ImageSwitcher mSwitcher;/*创建图片适配器 */public class ImageAdapter extends BaseAdapter public ImageAdapter(Context c)mContext=c;public int getCount()return mThumbIds.length;public Object getItem(int position)return position;public long getItemId(int position)return position;public View getView(int position,View convertView,ViewGroup parent)ImageView i=new ImageView(mContext);i.setImageResource(mThumbIdsposition);i.setAdjustViewBounds(true);i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT);i.setBackgroundResource(R.drawable.icon);return i;private Context mContext;/*存放图片,mThumbIds 为低分辨率图片,mImageIds 为高分辨率图片*/private Integer mThumbIds=名师资料总结-精品资料欢迎下载-名师精心整理-第 3 页,共 6 页 -R.drawable.ps1,R.drawable.ps2,R.drawable.ps3,R.drawable.ps4;private Integer mImageIds=R.drawable.p1,R.drawable.p2,R.drawable.p3,R.drawable.p4;package com.android.lrw;import android.app.Activity;import android.content.Intent;import android.os.Bundle;import android.v iew.View;import android.v iew.View.OnClickListener;import android.widget.Button;public class Android_ImgViewActivity extends Activity Override public void onCreate(Bundle savedInstanceState)super.onCreate(savedInstanceState);setContentView(R.layout.main);Button mybutton=(Button)findViewById(R.id.imageButton);调用监听器类mybutton.setOnClickListener(new ImageButtonListener();创建监听器内部类ImageButtonListener class ImageButtonListener implements OnClickListener Override public void onClick(View v)Intent intent=new Intent();intent.putExtra(value,jigsdhgiu);intent.setClass(Android_ImgViewActivity.this,ImgShowActivity.class);startActivity(intent);Main.xml代码 imageshow.xml 代码 注册 Ativity 名师资料总结-精品资料欢迎下载-名师精心整理-第 5 页,共 6 页 -名师资料总结-精品资料欢迎下载-名师精心整理-第 6 页,共 6 页 -。

下载提示
相似文档
正为您匹配相似的精品文档
相关文档