Python特殊语法:filter、map、reduce、lambda [转]
2015-03-19 16:51
519 查看
图片切换ImageSwitcher的使用:
package com.Aina.Android; import android.app.Activity; import android.os.Bundle; import android.util.Log; import android.view.View; import android.view.View.OnClickListener; import android.widget.Button; import android.widget.ImageSwitcher; import android.widget.ImageView; import android.widget.LinearLayout; import android.widget.ViewSwitcher.ViewFactory; public class Test_ImageSwitcher extends Activity implements OnClickListener,ViewFactory{ /** Called when the activity is first created. */ //所有要显示的图片资源索引 private static final Integer[] imagelist = { R.drawable.img1, R.drawable.img2, R.drawable.img3, R.drawable.img4, R.drawable.img5, R.drawable.img6, R.drawable.img7, R.drawable.img8 }; private ImageSwitcher imageswitcher; private static int index = 0; //设置各组件ID private static final int Button_NEXT = 0x123456; private static final int Button_BACK = 0x123457; private static final int ImageSwitcher = 0x123458; @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); //创建一个线性布局 LinearLayout layout = new LinearLayout(this); layout.setOrientation(LinearLayout.HORIZONTAL);//水平布局 imageswitcher = new ImageSwitcher(this); LinearLayout.LayoutParams p2 = new LinearLayout.LayoutParams(120,120); layout.addView(imageswitcher,p2); imageswitcher.setId(ImageSwitcher);//设置ID imageswitcher.setFactory(this);//设置此对象的数据源 imageswitcher.setImageResource(imagelist[index]); setContentView(layout); //创建下一张按钮 Button next = new Button(this); next.setId(Button_NEXT); next.setText("下一张"); next.setOnClickListener(this); LinearLayout.LayoutParams p = new LinearLayout.LayoutParams(100,100); layout.addView(next, p); //创建上一张按钮 Button back = new Button(this); back.setId(Button_BACK); back.setText("上一张"); back.setOnClickListener(this); layout.addView(back, p); } @Override public void onClick(View v) { if(v.getId()==Button_BACK){ index--; if(index<0){ index = imagelist.length-1; } imageswitcher.setImageResource(imagelist[index]); }else if(v.getId()==Button_NEXT){ index++; if(index>=imagelist.length){ index = 0; } imageswitcher.setImageResource(imagelist[index]); } } @Override public View makeView() { Log.i("TAG", "makeView()"); return new ImageView(this); } }
相关文章推荐
- Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda、yield
- Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda(转)
- function返回值Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda
- Python特殊语法这之:filter、map、reduce、lambda(转自“玩玩python”)
- Python特殊语法:filter、map、reduce、lambda [转]
- Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda [转]
- Python特殊语法:filter、map、reduce、lambda
- 【ZZ】Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda [转]
- Python特殊语法:filter、map、reduce、lambda、yield
- 【转】Python特殊语法:filter、map、reduce、lambda
- [转]Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda
- Python特殊语法:filter、map、reduce、lambda