-
SeekBar主要属性以及方法查看全部
-
ViewFactory的使用查看全部
-
五.實現接口ViewFactorypublic class MainActivity extends Activity implements OnItemSelectedListener,ViewFactory{ @Override public View makeView() { // TODO Auto-generated method stub ImageView image=new ImageView(this); image.setScaleType(ScaleType.FIT_CENTER); return image; } } 六.設定ImageSwicher的切換效果 is.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); is.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out));查看全部
-
ImageSwither介绍查看全部
-
四、實現OnItemSelectedListener接口public class MainActivity extends Activity implements OnItemSelectedListener查看全部
-
三、MainActivity:(接上條筆記) @Override public void onItemSelected(AdapterView<?> parent, View view, int position, long id) { // TODO Auto-generated method stub //image.setBackgroundResource(res[position%res.length]); is.setBackgroundResource(res[position%res.length]); } @Override public void onNothingSelected(AdapterView<?> parent) { // TODO Auto-generated method stub } @Override public View makeView() { // TODO Auto-generated method stub ImageView image=new ImageView(this); image.setScaleType(ScaleType.FIT_CENTER); return image; } }查看全部
-
三、MainActivity: public class MainActivity extends Activity implements OnItemSelectedListener,ViewFactory{ // 准备数据源 private int[] res = { 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 }; private ImageAdapter adapter; private Gallery gallery; private ImageSwitcher is; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); gallery = (Gallery) findViewById(R.id.gallery); is=(ImageSwitcher) findViewById(R.id.is); // gallery加载适配器 adapter = new ImageAdapter(res, this); gallery.setAdapter(adapter); gallery.setOnItemSelectedListener(this); is.setFactory(this); is.setInAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_in)); is.setOutAnimation(AnimationUtils.loadAnimation(this, android.R.anim.fade_out)); }查看全部
-
二、自定義數據適配器imageAdapter: public class ImageAdapter extends BaseAdapter{ private int[]res; private Context context; public ImageAdapter(int []res,Context context) { this.res=res; this.context=context; } //返回数据源的数量 @Override public int getCount() { // TODO Auto-generated method stub return Integer.MAX_VALUE; } @Override public Object getItem(int position) { // TODO Auto-generated method stub return res[position]; } @Override public long getItemId(int position) { // TODO Auto-generated method stub return position; } @Override public View getView(int position, View convertView, ViewGroup parent) { Log.i("Main", "position="+position+"res的角标="+position%res.length); ImageView image=new ImageView(context); image.setBackgroundResource(res[position%res.length]); //給每個縮略圖設定大小 image.setLayoutParams(new Gallery.LayoutParams(200, 150)); //縮放的模式是XY粥縮放型的 image.setScaleType(ScaleType.FIT_XY); return image; } }查看全部
-
BaseAdapter中的重要方法查看全部
-
一、 <Gallery android:id="@+id/gallery" android:layout_width="match_parent" android:layout_height="wrap_content" />查看全部
-
案例預覽查看全部
-
Gallery介紹查看全部
-
配置Adapter查看全部
-
将Layout布局转换为View对象查看全部
-
一、实现接口public class MainActivity extends Activity implements OnClickListener 二、@Override public void onClick(View v) { // TODO Auto-generated method stub switch (v.getId()) { // scrollTo:以滚动视图起始位置开始计算的 // scrollBy:相对前一次的位置,去滚动对应的距离 case R.id.up: { scroll.scrollBy(0, -30); break; } case R.id.down: { scroll.scrollBy(0, 30); break; } } }查看全部
举报
0/150
提交
取消