添加 imageview 两种方式

package com.zj;

import android.app.Activity;

import android.graphics.Bitmap;

import android.graphics.BitmapFactory;

import android.os.Bundle;

import android.widget.ImageView;

import android.widget.LinearLayout;

import android.widget.TextView;

public class TestTestActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        

        setContentView(R.layout.main);

        LinearLayout lineLayout = (LinearLayout)findViewById(R.id.main_layout);

        ImageView imageView = new ImageView(this);

        

//      imageView.setBackgroundResource(R.drawable.icon);//形式一setBackgroundResource

        Bitmap sourcePicture = BitmapFactory.decodeResource(getResources(), R.drawable.icon);//形式二得到图片

        imageView.setImageBitmap(sourcePicture);

        

        lineLayout.addView(imageView);

        

    }

}

posted @ 2011-08-05 20:55  镇水古月  阅读(705)  评论(0编辑  收藏  举报