资源预览内容
第1页 / 共3页
第2页 / 共3页
第3页 / 共3页
亲,该文档总共3页全部预览完了,如果喜欢就下载吧!
资源描述
MainActivity.javapackage com.example.aaa;import android.os.Bundle;import android.app.Activity;import android.widget.Gallery;public class MainActivity extends Activity Gallery gallery;Overrideprotected void onCreate(Bundle savedInstanceState) super.onCreate(savedInstanceState);setContentView(R.layout.activity_main);gallery=(Gallery) findViewById(R.id.gallery1);gallery.setAdapter(new MyAdapter(this);gallery.setSelection(1);MyAdapter.javapackage com.example.aaa;import android.content.Context;import android.view.View;import android.view.ViewGroup;import android.widget.BaseAdapter;import android.widget.Gallery;import android.widget.ImageView;public class MyAdapter extends BaseAdapter private Context mContext;private int imgs=R.drawable.mm0,R.drawable.mm1,R.drawable.mm2,;public MyAdapter(Context c) super();/ TODO Auto-generated constructor stubmContext=c;Overridepublic int getCount() / TODO Auto-generated method stubreturn imgs.length;Overridepublic Object getItem(int position) / TODO Auto-generated method stubreturn position;Overridepublic long getItemId(int position) / TODO Auto-generated method stubreturn position;Overridepublic View getView(int position, View convertView, ViewGroup parent) / TODO Auto-generated method stubImageView iv=new ImageView(mContext);iv.setBackgroundResource(imgsposition);iv.setAdjustViewBounds(true);iv.setLayoutParams(new Gallery.LayoutParams(300, 250);return iv;main.xml 文档结束peng
收藏 下载该资源
网站客服QQ:2055934822
金锄头文库版权所有
经营许可证:蜀ICP备13022795号 | 川公网安备 51140202000112号