日本黄色一级经典视频|伊人久久精品视频|亚洲黄色色周成人视频九九九|av免费网址黄色小短片|黄色Av无码亚洲成年人|亚洲1区2区3区无码|真人黄片免费观看|无码一级小说欧美日免费三级|日韩中文字幕91在线看|精品久久久无码中文字幕边打电话

當(dāng)前位置:首頁(yè) > 芯聞號(hào) > 充電吧
[導(dǎo)讀]galleryAdapter.javapackage?com.example.administrator.gallery; import?android.content.Context; impor

galleryAdapter.java

package?com.example.administrator.gallery;

import?android.content.Context;
import?android.view.View;
import?android.view.ViewGroup;
import?android.widget.BaseAdapter;
import?android.widget.Gallery;
import?android.widget.ImageView;

/**
?*?Created?by?Administrator?on?2015/7/23.
?*/
public?class?galleryAdapter?extends?BaseAdapter{
????private?int[]?resId;
????private?Context?mContext;

????public?galleryAdapter(int[]?resId,Context?mContext)?{
????????this.resId?=?resId;
????????this.mContext?=?mContext;
????}

????@Override
????public?int?getCount()?{
//????????return?resId.length;
????????return?Integer.MAX_VALUE;?//讓gallery循環(huán),所以設(shè)置為最大數(shù)
????}


????@Override
????public?Object?getItem(int?position)?{
????????return?resId[position];
????}

????@Override
????public?long?getItemId(int?position)?{
????????return?position;
????}

????@Override
????public?View?getView(int?position,?View?convertView,?ViewGroup?parent)?{
????????ImageView?img?=?new?ImageView(mContext);
//????????img.setBackgroundResource(resId[position]);
????????img.setBackgroundResource(resId[position?%?resId.length]);?//循環(huán)

????????//設(shè)置縮放
//????????img.setLayoutParams(new?Gallery.LayoutParams(300,400));
//????????img.setScaleType(ImageView.ScaleType.FIT_XY);

????????return?img;
????}
}

MainActivity.java

package?com.example.administrator.gallery;

import?android.support.v7.app.ActionBarActivity;
import?android.os.Bundle;
import?android.view.Menu;
import?android.view.MenuItem;
import?android.view.View;
import?android.view.animation.Animation;
import?android.view.animation.AnimationUtils;
import?android.widget.AdapterView;
import?android.widget.Gallery;
import?android.widget.ImageSwitcher;
import?android.widget.ImageView;
import?android.widget.ViewSwitcher;


public?class?MainActivity?extends?ActionBarActivity?implements?ViewSwitcher.ViewFactory{
????private?Gallery?gallery;
????private?ImageSwitcher?switcher;
????private?int[]?resId?=?new?int[]{R.drawable.item1,R.drawable.item2,R.drawable.item3,R.drawable.item4,R.drawable.item5,R.drawable.item6,R.drawable.item7,R.drawable.item8,R.drawable.item9,R.drawable.item10,R.drawable.item11,R.drawable.item12};


????@Override
????protected?void?onCreate(Bundle?savedInstanceState)?{
????????super.onCreate(savedInstanceState);
????????setContentView(R.layout.activity_main);

????????gallery?=?(Gallery)findViewById(R.id.gallery);
????????switcher?=?(ImageSwitcher)findViewById(R.id.switcher);

????????galleryAdapter?adapter?=?new?galleryAdapter(resId,this);
????????gallery.setAdapter(adapter);


????????gallery.setOnItemSelectedListener(new?Gallery.OnItemSelectedListener()?{
????????????@Override
????????????public?void?onItemSelected(AdapterView?parent,?View?view,?int?position,?long?id)?{
//????????????????img.setBackgroundResource(resId[position?%?resId.length]);?//循環(huán)
????????????????switcher.setBackgroundResource(resId[position?%?resId.length]);
????????????}

????????????@Override
????????????public?void?onNothingSelected(AdapterView?parent)?{

????????????}
????????});

????????//ImageSwitcher加載工廠
????????switcher.setFactory(this);
????????//動(dòng)畫(huà)效果
????????switcher.setInAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_in));
????????switcher.setOutAnimation(AnimationUtils.loadAnimation(this,android.R.anim.fade_out));

????}


????@Override
????public?View?makeView()?{
????????ImageView?img?=?new?ImageView(this);
????????img.setScaleType(ImageView.ScaleType.FIT_CENTER);
????????return?img;
????}
}

本站聲明: 本文章由作者或相關(guān)機(jī)構(gòu)授權(quán)發(fā)布,目的在于傳遞更多信息,并不代表本站贊同其觀點(diǎn),本站亦不保證或承諾內(nèi)容真實(shí)性等。需要轉(zhuǎn)載請(qǐng)聯(lián)系該專(zhuān)欄作者,如若文章內(nèi)容侵犯您的權(quán)益,請(qǐng)及時(shí)聯(lián)系本站刪除( 郵箱:macysun@21ic.com )。
換一批
延伸閱讀
關(guān)閉