关闭

AdapterViewFlipper的用法

标签: AdapterViewFlipper
61人阅读 评论(0) 收藏 举报
分类:
import android.support.v7.app.ActionBarActivity;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.view.ViewGroup;
import android.view.ViewGroup.LayoutParams;
import android.widget.AdapterViewFlipper;
import android.widget.BaseAdapter;
import android.widget.ImageView;


public class MainActivity extends Activity {

int[] imageIds=new int[]{
R.drawable.w_001,
R.drawable.w_002,
R.drawable.w_003,
R.drawable.w_004,
R.drawable.w_005,
R.drawable.w_006,
};


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

flipper=(AdapterViewFlipper)findViewById(R.id.flipper);

BaseAdapter adapter=new BaseAdapter()
{


@Override
public int getCount() {

return imageIds.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) {
ImageView imageView=new ImageView(MainActivity.this);
imageView.setImageResource(imageIds[position]);
imageView.setScaleType(ImageView.ScaleType.FIT_XY);
imageView.setLayoutParams(new ViewGroup.LayoutParams(LayoutParams.MATCH_PARENT,LayoutParams.MATCH_PARENT));
return imageView;
}

};
flipper.setAdapter(adapter);
}
public void prev(View source){
flipper.showPrevious();
flipper.stopFlipping();
}
public void next(View source){
flipper.showNext();
flipper.stopFlipping();
}
public void auto(View source){
flipper.startFlipping();
}
}
1
0

查看评论
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
    个人资料
    • 访问:836次
    • 积分:55
    • 等级:
    • 排名:千里之外
    • 原创:4篇
    • 转载:4篇
    • 译文:0篇
    • 评论:0条
    文章分类