第一步:顯示一張圖片:方法一、public class PicshowMainActivity extends Activity {LinearLayout mLinearLayout;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.mLinearLayout = new LinearLayout(this);ImageView i = new ImageView(this);i.setImageResource(R.drawable.hehua);i.setAdjustViewBounds(true);i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));mLinearLayout.addView(i);setContentView(mLinearLayout);//setContentView(R.layout.main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
方法二:
public class PicshowMainActivity extends Activity {LinearLayout mLinearLayout;@Overrideprotected void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);this.mLinearLayout = new LinearLayout(this);ImageView i = new ImageView(this);//i.setAdjustViewBounds(adjustViewBounds)//i.setImageResource(R.drawable.hehua);i.setAdjustViewBounds(true);i.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT,LayoutParams.WRAP_CONTENT));//mLinearLayout.addView(i);//setContentView(mLinearLayout);//ContextWrapper mContext = null;Resources res = getResources();Drawable myImage = res.getDrawable(R.drawable.baihehua);//TransitionDrawable transition = (TransitionDrawable)res.getDrawable(R.drawable.hehua);//TransitionDrawable transition =//(TransitionDrawable) res.getDrawable(R.drawable.next);//i.setImageDrawable(transition);i.setImageDrawable(myImage);//transition.startTransition(10000);mLinearLayout.addView(i);setContentView(mLinearLayout);//setContentView(R.layout.main);}@Overridepublic boolean onCreateOptionsMenu(Menu menu) {// Inflate the menu; this adds items to the action bar if it is present.getMenuInflater().inflate(R.menu.main, menu);return true;}}
方法三:
是控制項顯示 略