ImageView Programmatically
public class Cq_Img01Activity extends Activity {
/** Called when the activity is first created. */
LinearLayout mLinearLayout;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
//Create a LinearLayout for ImageView
mLinearLayout = new LinearLayout(this);
//Create ImageView obj
ImageView imageview = new ImageView(this);
imageview.setImageResource(R.drawable.imgexample);
//Set size
imageview.setAdjustViewBounds(true);
imageview.setLayoutParams(new Gallery.LayoutParams(LayoutParams.WRAP_CONTENT, LayoutParams.WRAP_CONTENT));
mLinearLayout.addView(imageview);
setContentView(mLinearLayout);
}
}
沒有留言:
張貼留言